mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 05:24:51 +00:00
refactor: rename integer
This commit is contained in:
parent
2ae4db14f6
commit
738a7ff2b9
2 changed files with 35 additions and 5 deletions
|
@ -19,7 +19,7 @@ fn basic() {
|
|||
let mut container = loro.get_or_create_root_map("map").unwrap();
|
||||
container.insert("haha".into(), InsertValue::Int32(1));
|
||||
let ans = fx_map!(
|
||||
"haha".into() => LoroValue::Integer(1)
|
||||
"haha".into() => LoroValue::I32(1)
|
||||
);
|
||||
|
||||
assert_eq!(container.get_value(), LoroValue::Map(Box::new(ans)));
|
||||
|
|
|
@ -9,7 +9,7 @@ pub enum LoroValue {
|
|||
Null,
|
||||
Bool(bool),
|
||||
Double(f64),
|
||||
Integer(i32),
|
||||
I32(i32),
|
||||
String(Box<str>),
|
||||
List(Box<Vec<LoroValue>>),
|
||||
Map(Box<FxHashMap<InternalString, LoroValue>>),
|
||||
|
@ -40,7 +40,7 @@ impl From<InsertValue> for LoroValue {
|
|||
InsertValue::Null => LoroValue::Null,
|
||||
InsertValue::Bool(b) => LoroValue::Bool(b),
|
||||
InsertValue::Double(d) => LoroValue::Double(d),
|
||||
InsertValue::Int32(i) => LoroValue::Integer(i),
|
||||
InsertValue::Int32(i) => LoroValue::I32(i),
|
||||
InsertValue::String(s) => LoroValue::String(s),
|
||||
InsertValue::Container(c) => LoroValue::Unresolved(c),
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl From<LoroValue> for InsertValue {
|
|||
LoroValue::Null => InsertValue::Null,
|
||||
LoroValue::Bool(b) => InsertValue::Bool(b),
|
||||
LoroValue::Double(d) => InsertValue::Double(d),
|
||||
LoroValue::Integer(i) => InsertValue::Int32(i),
|
||||
LoroValue::I32(i) => InsertValue::Int32(i),
|
||||
LoroValue::String(s) => InsertValue::String(s),
|
||||
LoroValue::Unresolved(c) => InsertValue::Container(c),
|
||||
_ => unreachable!("Unsupported convert from LoroValue to InsertValue"),
|
||||
|
@ -61,6 +61,36 @@ impl From<LoroValue> for InsertValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<i32> for LoroValue {
|
||||
fn from(v: i32) -> Self {
|
||||
LoroValue::I32(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for LoroValue {
|
||||
fn from(v: f64) -> Self {
|
||||
LoroValue::Double(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for LoroValue {
|
||||
fn from(v: bool) -> Self {
|
||||
LoroValue::Bool(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for LoroValue {
|
||||
fn from(v: &str) -> Self {
|
||||
LoroValue::String(v.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for LoroValue {
|
||||
fn from(v: String) -> Self {
|
||||
LoroValue::String(v.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// [InsertValue] can be inserted to Map or List
|
||||
/// It's different from [LoroValue] because some of the states in [LoroValue] are illegal to be inserted
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
@ -87,7 +117,7 @@ pub mod wasm {
|
|||
LoroValue::Null => JsValue::NULL,
|
||||
LoroValue::Bool(b) => JsValue::from_bool(b),
|
||||
LoroValue::Double(f) => JsValue::from_f64(f),
|
||||
LoroValue::Integer(i) => JsValue::from_f64(i as f64),
|
||||
LoroValue::I32(i) => JsValue::from_f64(i as f64),
|
||||
LoroValue::String(s) => JsValue::from_str(&s),
|
||||
LoroValue::List(list) => {
|
||||
let arr = Array::new_with_length(list.len() as u32);
|
||||
|
|
Loading…
Reference in a new issue