pub enum LinoValue {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Array(Vec<LinoValue>),
Object(Vec<(String, LinoValue)>),
}Expand description
A value that can be encoded/decoded using the Links Notation codec.
This type supports all the types available in Python/JavaScript versions including special float values (NaN, Infinity) that are not valid JSON.
Variants§
Null
Null value
Bool(bool)
Boolean value
Int(i64)
Integer value (64-bit signed)
Float(f64)
Floating point value (64-bit)
String(String)
String value
Array(Vec<LinoValue>)
Array of values
Object(Vec<(String, LinoValue)>)
Object/dictionary with string keys
Implementations§
Source§impl LinoValue
impl LinoValue
Sourcepub fn object<I, K, V>(iter: I) -> Self
pub fn object<I, K, V>(iter: I) -> Self
Create an object from an iterator of key-value pairs.
Examples found in repository?
examples/basic_usage.rs (lines 96-100)
5fn main() {
6 println!("=== Links Notation Objects Codec - Rust Example ===\n");
7
8 // Example 1: Basic types
9 println!("1. Basic Types:");
10
11 // Null
12 let null_val = LinoValue::Null;
13 let encoded = encode(&null_val);
14 println!(
15 " Null: {} -> decoded: {:?}",
16 encoded,
17 decode(&encoded).unwrap()
18 );
19
20 // Booleans
21 let true_val = LinoValue::Bool(true);
22 let encoded = encode(&true_val);
23 println!(
24 " true: {} -> decoded: {:?}",
25 encoded,
26 decode(&encoded).unwrap()
27 );
28
29 // Integers
30 let int_val = LinoValue::Int(42);
31 let encoded = encode(&int_val);
32 println!(
33 " 42: {} -> decoded: {:?}",
34 encoded,
35 decode(&encoded).unwrap()
36 );
37
38 // Floats
39 let float_val = LinoValue::Float(3.14159);
40 let encoded = encode(&float_val);
41 println!(
42 " 3.14159: {} -> decoded: {:?}",
43 encoded,
44 decode(&encoded).unwrap()
45 );
46
47 // Special floats
48 let inf_val = LinoValue::Float(f64::INFINITY);
49 let encoded = encode(&inf_val);
50 println!(
51 " Infinity: {} -> decoded: {:?}",
52 encoded,
53 decode(&encoded).unwrap()
54 );
55
56 let nan_val = LinoValue::Float(f64::NAN);
57 let encoded = encode(&nan_val);
58 let decoded = decode(&encoded).unwrap();
59 println!(
60 " NaN: {} -> decoded is_nan: {}",
61 encoded,
62 decoded.as_float().unwrap().is_nan()
63 );
64
65 // Strings
66 let str_val = LinoValue::String("Hello, World!".to_string());
67 let encoded = encode(&str_val);
68 println!(
69 " 'Hello, World!': {} -> decoded: {:?}",
70 encoded,
71 decode(&encoded).unwrap()
72 );
73
74 // Unicode strings
75 let unicode_val = LinoValue::String("你好世界 🌍".to_string());
76 let encoded = encode(&unicode_val);
77 println!(
78 " Unicode: {} -> decoded: {:?}",
79 encoded,
80 decode(&encoded).unwrap()
81 );
82
83 println!();
84
85 // Example 2: Collections
86 println!("2. Collections:");
87
88 // Array
89 let array_val = LinoValue::array([LinoValue::Int(1), LinoValue::Int(2), LinoValue::Int(3)]);
90 let encoded = encode(&array_val);
91 let decoded = decode(&encoded).unwrap();
92 println!(" Array [1, 2, 3]: {}", encoded);
93 println!(" Decoded: {:?}", decoded);
94
95 // Object
96 let obj_val = LinoValue::object([
97 ("name", LinoValue::String("Alice".to_string())),
98 ("age", LinoValue::Int(30)),
99 ("active", LinoValue::Bool(true)),
100 ]);
101 let encoded = encode(&obj_val);
102 let decoded = decode(&encoded).unwrap();
103 println!(" Object {{name, age, active}}: {}", encoded);
104 println!(" Decoded: {:?}", decoded);
105
106 println!();
107
108 // Example 3: Nested structures
109 println!("3. Nested Structure:");
110
111 let complex = LinoValue::object([
112 ("id", LinoValue::Int(123)),
113 ("name", LinoValue::String("Test Object".to_string())),
114 (
115 "tags",
116 LinoValue::array([
117 LinoValue::String("tag1".to_string()),
118 LinoValue::String("tag2".to_string()),
119 ]),
120 ),
121 (
122 "metadata",
123 LinoValue::object([
124 ("version", LinoValue::Int(1)),
125 ("created", LinoValue::String("2025-01-01".to_string())),
126 ]),
127 ),
128 ]);
129
130 let encoded = encode(&complex);
131 let decoded = decode(&encoded).unwrap();
132
133 println!(" Encoded: {}", encoded);
134 println!(" Decoded name: {:?}", decoded.get("name"));
135 println!(" Decoded tags: {:?}", decoded.get("tags"));
136 println!(
137 " Decoded metadata.version: {:?}",
138 decoded.get("metadata").and_then(|m| m.get("version"))
139 );
140
141 println!();
142
143 // Example 4: Mixed type array
144 println!("4. Mixed Type Array:");
145
146 let mixed = LinoValue::array([
147 LinoValue::Int(1),
148 LinoValue::String("hello".to_string()),
149 LinoValue::Bool(true),
150 LinoValue::Null,
151 LinoValue::Float(2.5),
152 ]);
153
154 let encoded = encode(&mixed);
155 let decoded = decode(&encoded).unwrap();
156
157 println!(" Encoded: {}", encoded);
158 println!(" Decoded: {:?}", decoded);
159
160 println!();
161
162 // Example 5: Roundtrip verification
163 println!("5. Roundtrip Verification:");
164
165 let data = LinoValue::object([
166 (
167 "users",
168 LinoValue::array([
169 LinoValue::object([
170 ("id", LinoValue::Int(1)),
171 ("name", LinoValue::String("Alice".to_string())),
172 ]),
173 LinoValue::object([
174 ("id", LinoValue::Int(2)),
175 ("name", LinoValue::String("Bob".to_string())),
176 ]),
177 ]),
178 ),
179 ("count", LinoValue::Int(2)),
180 ]);
181
182 let encoded = encode(&data);
183 let decoded = decode(&encoded).unwrap();
184
185 println!(" Original == Decoded: {}", data == decoded);
186
187 println!("\n=== Example completed successfully! ===");
188}Sourcepub fn array<I, V>(iter: I) -> Self
pub fn array<I, V>(iter: I) -> Self
Create an array from an iterator of values.
Examples found in repository?
examples/basic_usage.rs (line 89)
5fn main() {
6 println!("=== Links Notation Objects Codec - Rust Example ===\n");
7
8 // Example 1: Basic types
9 println!("1. Basic Types:");
10
11 // Null
12 let null_val = LinoValue::Null;
13 let encoded = encode(&null_val);
14 println!(
15 " Null: {} -> decoded: {:?}",
16 encoded,
17 decode(&encoded).unwrap()
18 );
19
20 // Booleans
21 let true_val = LinoValue::Bool(true);
22 let encoded = encode(&true_val);
23 println!(
24 " true: {} -> decoded: {:?}",
25 encoded,
26 decode(&encoded).unwrap()
27 );
28
29 // Integers
30 let int_val = LinoValue::Int(42);
31 let encoded = encode(&int_val);
32 println!(
33 " 42: {} -> decoded: {:?}",
34 encoded,
35 decode(&encoded).unwrap()
36 );
37
38 // Floats
39 let float_val = LinoValue::Float(3.14159);
40 let encoded = encode(&float_val);
41 println!(
42 " 3.14159: {} -> decoded: {:?}",
43 encoded,
44 decode(&encoded).unwrap()
45 );
46
47 // Special floats
48 let inf_val = LinoValue::Float(f64::INFINITY);
49 let encoded = encode(&inf_val);
50 println!(
51 " Infinity: {} -> decoded: {:?}",
52 encoded,
53 decode(&encoded).unwrap()
54 );
55
56 let nan_val = LinoValue::Float(f64::NAN);
57 let encoded = encode(&nan_val);
58 let decoded = decode(&encoded).unwrap();
59 println!(
60 " NaN: {} -> decoded is_nan: {}",
61 encoded,
62 decoded.as_float().unwrap().is_nan()
63 );
64
65 // Strings
66 let str_val = LinoValue::String("Hello, World!".to_string());
67 let encoded = encode(&str_val);
68 println!(
69 " 'Hello, World!': {} -> decoded: {:?}",
70 encoded,
71 decode(&encoded).unwrap()
72 );
73
74 // Unicode strings
75 let unicode_val = LinoValue::String("你好世界 🌍".to_string());
76 let encoded = encode(&unicode_val);
77 println!(
78 " Unicode: {} -> decoded: {:?}",
79 encoded,
80 decode(&encoded).unwrap()
81 );
82
83 println!();
84
85 // Example 2: Collections
86 println!("2. Collections:");
87
88 // Array
89 let array_val = LinoValue::array([LinoValue::Int(1), LinoValue::Int(2), LinoValue::Int(3)]);
90 let encoded = encode(&array_val);
91 let decoded = decode(&encoded).unwrap();
92 println!(" Array [1, 2, 3]: {}", encoded);
93 println!(" Decoded: {:?}", decoded);
94
95 // Object
96 let obj_val = LinoValue::object([
97 ("name", LinoValue::String("Alice".to_string())),
98 ("age", LinoValue::Int(30)),
99 ("active", LinoValue::Bool(true)),
100 ]);
101 let encoded = encode(&obj_val);
102 let decoded = decode(&encoded).unwrap();
103 println!(" Object {{name, age, active}}: {}", encoded);
104 println!(" Decoded: {:?}", decoded);
105
106 println!();
107
108 // Example 3: Nested structures
109 println!("3. Nested Structure:");
110
111 let complex = LinoValue::object([
112 ("id", LinoValue::Int(123)),
113 ("name", LinoValue::String("Test Object".to_string())),
114 (
115 "tags",
116 LinoValue::array([
117 LinoValue::String("tag1".to_string()),
118 LinoValue::String("tag2".to_string()),
119 ]),
120 ),
121 (
122 "metadata",
123 LinoValue::object([
124 ("version", LinoValue::Int(1)),
125 ("created", LinoValue::String("2025-01-01".to_string())),
126 ]),
127 ),
128 ]);
129
130 let encoded = encode(&complex);
131 let decoded = decode(&encoded).unwrap();
132
133 println!(" Encoded: {}", encoded);
134 println!(" Decoded name: {:?}", decoded.get("name"));
135 println!(" Decoded tags: {:?}", decoded.get("tags"));
136 println!(
137 " Decoded metadata.version: {:?}",
138 decoded.get("metadata").and_then(|m| m.get("version"))
139 );
140
141 println!();
142
143 // Example 4: Mixed type array
144 println!("4. Mixed Type Array:");
145
146 let mixed = LinoValue::array([
147 LinoValue::Int(1),
148 LinoValue::String("hello".to_string()),
149 LinoValue::Bool(true),
150 LinoValue::Null,
151 LinoValue::Float(2.5),
152 ]);
153
154 let encoded = encode(&mixed);
155 let decoded = decode(&encoded).unwrap();
156
157 println!(" Encoded: {}", encoded);
158 println!(" Decoded: {:?}", decoded);
159
160 println!();
161
162 // Example 5: Roundtrip verification
163 println!("5. Roundtrip Verification:");
164
165 let data = LinoValue::object([
166 (
167 "users",
168 LinoValue::array([
169 LinoValue::object([
170 ("id", LinoValue::Int(1)),
171 ("name", LinoValue::String("Alice".to_string())),
172 ]),
173 LinoValue::object([
174 ("id", LinoValue::Int(2)),
175 ("name", LinoValue::String("Bob".to_string())),
176 ]),
177 ]),
178 ),
179 ("count", LinoValue::Int(2)),
180 ]);
181
182 let encoded = encode(&data);
183 let decoded = decode(&encoded).unwrap();
184
185 println!(" Original == Decoded: {}", data == decoded);
186
187 println!("\n=== Example completed successfully! ===");
188}Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Get as a float, if this is a float or int.
Examples found in repository?
examples/basic_usage.rs (line 62)
5fn main() {
6 println!("=== Links Notation Objects Codec - Rust Example ===\n");
7
8 // Example 1: Basic types
9 println!("1. Basic Types:");
10
11 // Null
12 let null_val = LinoValue::Null;
13 let encoded = encode(&null_val);
14 println!(
15 " Null: {} -> decoded: {:?}",
16 encoded,
17 decode(&encoded).unwrap()
18 );
19
20 // Booleans
21 let true_val = LinoValue::Bool(true);
22 let encoded = encode(&true_val);
23 println!(
24 " true: {} -> decoded: {:?}",
25 encoded,
26 decode(&encoded).unwrap()
27 );
28
29 // Integers
30 let int_val = LinoValue::Int(42);
31 let encoded = encode(&int_val);
32 println!(
33 " 42: {} -> decoded: {:?}",
34 encoded,
35 decode(&encoded).unwrap()
36 );
37
38 // Floats
39 let float_val = LinoValue::Float(3.14159);
40 let encoded = encode(&float_val);
41 println!(
42 " 3.14159: {} -> decoded: {:?}",
43 encoded,
44 decode(&encoded).unwrap()
45 );
46
47 // Special floats
48 let inf_val = LinoValue::Float(f64::INFINITY);
49 let encoded = encode(&inf_val);
50 println!(
51 " Infinity: {} -> decoded: {:?}",
52 encoded,
53 decode(&encoded).unwrap()
54 );
55
56 let nan_val = LinoValue::Float(f64::NAN);
57 let encoded = encode(&nan_val);
58 let decoded = decode(&encoded).unwrap();
59 println!(
60 " NaN: {} -> decoded is_nan: {}",
61 encoded,
62 decoded.as_float().unwrap().is_nan()
63 );
64
65 // Strings
66 let str_val = LinoValue::String("Hello, World!".to_string());
67 let encoded = encode(&str_val);
68 println!(
69 " 'Hello, World!': {} -> decoded: {:?}",
70 encoded,
71 decode(&encoded).unwrap()
72 );
73
74 // Unicode strings
75 let unicode_val = LinoValue::String("你好世界 🌍".to_string());
76 let encoded = encode(&unicode_val);
77 println!(
78 " Unicode: {} -> decoded: {:?}",
79 encoded,
80 decode(&encoded).unwrap()
81 );
82
83 println!();
84
85 // Example 2: Collections
86 println!("2. Collections:");
87
88 // Array
89 let array_val = LinoValue::array([LinoValue::Int(1), LinoValue::Int(2), LinoValue::Int(3)]);
90 let encoded = encode(&array_val);
91 let decoded = decode(&encoded).unwrap();
92 println!(" Array [1, 2, 3]: {}", encoded);
93 println!(" Decoded: {:?}", decoded);
94
95 // Object
96 let obj_val = LinoValue::object([
97 ("name", LinoValue::String("Alice".to_string())),
98 ("age", LinoValue::Int(30)),
99 ("active", LinoValue::Bool(true)),
100 ]);
101 let encoded = encode(&obj_val);
102 let decoded = decode(&encoded).unwrap();
103 println!(" Object {{name, age, active}}: {}", encoded);
104 println!(" Decoded: {:?}", decoded);
105
106 println!();
107
108 // Example 3: Nested structures
109 println!("3. Nested Structure:");
110
111 let complex = LinoValue::object([
112 ("id", LinoValue::Int(123)),
113 ("name", LinoValue::String("Test Object".to_string())),
114 (
115 "tags",
116 LinoValue::array([
117 LinoValue::String("tag1".to_string()),
118 LinoValue::String("tag2".to_string()),
119 ]),
120 ),
121 (
122 "metadata",
123 LinoValue::object([
124 ("version", LinoValue::Int(1)),
125 ("created", LinoValue::String("2025-01-01".to_string())),
126 ]),
127 ),
128 ]);
129
130 let encoded = encode(&complex);
131 let decoded = decode(&encoded).unwrap();
132
133 println!(" Encoded: {}", encoded);
134 println!(" Decoded name: {:?}", decoded.get("name"));
135 println!(" Decoded tags: {:?}", decoded.get("tags"));
136 println!(
137 " Decoded metadata.version: {:?}",
138 decoded.get("metadata").and_then(|m| m.get("version"))
139 );
140
141 println!();
142
143 // Example 4: Mixed type array
144 println!("4. Mixed Type Array:");
145
146 let mixed = LinoValue::array([
147 LinoValue::Int(1),
148 LinoValue::String("hello".to_string()),
149 LinoValue::Bool(true),
150 LinoValue::Null,
151 LinoValue::Float(2.5),
152 ]);
153
154 let encoded = encode(&mixed);
155 let decoded = decode(&encoded).unwrap();
156
157 println!(" Encoded: {}", encoded);
158 println!(" Decoded: {:?}", decoded);
159
160 println!();
161
162 // Example 5: Roundtrip verification
163 println!("5. Roundtrip Verification:");
164
165 let data = LinoValue::object([
166 (
167 "users",
168 LinoValue::array([
169 LinoValue::object([
170 ("id", LinoValue::Int(1)),
171 ("name", LinoValue::String("Alice".to_string())),
172 ]),
173 LinoValue::object([
174 ("id", LinoValue::Int(2)),
175 ("name", LinoValue::String("Bob".to_string())),
176 ]),
177 ]),
178 ),
179 ("count", LinoValue::Int(2)),
180 ]);
181
182 let encoded = encode(&data);
183 let decoded = decode(&encoded).unwrap();
184
185 println!(" Original == Decoded: {}", data == decoded);
186
187 println!("\n=== Example completed successfully! ===");
188}Sourcepub fn as_object(&self) -> Option<&Vec<(String, LinoValue)>>
pub fn as_object(&self) -> Option<&Vec<(String, LinoValue)>>
Get as an object, if this is an object.
Sourcepub fn get(&self, key: &str) -> Option<&LinoValue>
pub fn get(&self, key: &str) -> Option<&LinoValue>
Get a value from an object by key.
Examples found in repository?
examples/basic_usage.rs (line 134)
5fn main() {
6 println!("=== Links Notation Objects Codec - Rust Example ===\n");
7
8 // Example 1: Basic types
9 println!("1. Basic Types:");
10
11 // Null
12 let null_val = LinoValue::Null;
13 let encoded = encode(&null_val);
14 println!(
15 " Null: {} -> decoded: {:?}",
16 encoded,
17 decode(&encoded).unwrap()
18 );
19
20 // Booleans
21 let true_val = LinoValue::Bool(true);
22 let encoded = encode(&true_val);
23 println!(
24 " true: {} -> decoded: {:?}",
25 encoded,
26 decode(&encoded).unwrap()
27 );
28
29 // Integers
30 let int_val = LinoValue::Int(42);
31 let encoded = encode(&int_val);
32 println!(
33 " 42: {} -> decoded: {:?}",
34 encoded,
35 decode(&encoded).unwrap()
36 );
37
38 // Floats
39 let float_val = LinoValue::Float(3.14159);
40 let encoded = encode(&float_val);
41 println!(
42 " 3.14159: {} -> decoded: {:?}",
43 encoded,
44 decode(&encoded).unwrap()
45 );
46
47 // Special floats
48 let inf_val = LinoValue::Float(f64::INFINITY);
49 let encoded = encode(&inf_val);
50 println!(
51 " Infinity: {} -> decoded: {:?}",
52 encoded,
53 decode(&encoded).unwrap()
54 );
55
56 let nan_val = LinoValue::Float(f64::NAN);
57 let encoded = encode(&nan_val);
58 let decoded = decode(&encoded).unwrap();
59 println!(
60 " NaN: {} -> decoded is_nan: {}",
61 encoded,
62 decoded.as_float().unwrap().is_nan()
63 );
64
65 // Strings
66 let str_val = LinoValue::String("Hello, World!".to_string());
67 let encoded = encode(&str_val);
68 println!(
69 " 'Hello, World!': {} -> decoded: {:?}",
70 encoded,
71 decode(&encoded).unwrap()
72 );
73
74 // Unicode strings
75 let unicode_val = LinoValue::String("你好世界 🌍".to_string());
76 let encoded = encode(&unicode_val);
77 println!(
78 " Unicode: {} -> decoded: {:?}",
79 encoded,
80 decode(&encoded).unwrap()
81 );
82
83 println!();
84
85 // Example 2: Collections
86 println!("2. Collections:");
87
88 // Array
89 let array_val = LinoValue::array([LinoValue::Int(1), LinoValue::Int(2), LinoValue::Int(3)]);
90 let encoded = encode(&array_val);
91 let decoded = decode(&encoded).unwrap();
92 println!(" Array [1, 2, 3]: {}", encoded);
93 println!(" Decoded: {:?}", decoded);
94
95 // Object
96 let obj_val = LinoValue::object([
97 ("name", LinoValue::String("Alice".to_string())),
98 ("age", LinoValue::Int(30)),
99 ("active", LinoValue::Bool(true)),
100 ]);
101 let encoded = encode(&obj_val);
102 let decoded = decode(&encoded).unwrap();
103 println!(" Object {{name, age, active}}: {}", encoded);
104 println!(" Decoded: {:?}", decoded);
105
106 println!();
107
108 // Example 3: Nested structures
109 println!("3. Nested Structure:");
110
111 let complex = LinoValue::object([
112 ("id", LinoValue::Int(123)),
113 ("name", LinoValue::String("Test Object".to_string())),
114 (
115 "tags",
116 LinoValue::array([
117 LinoValue::String("tag1".to_string()),
118 LinoValue::String("tag2".to_string()),
119 ]),
120 ),
121 (
122 "metadata",
123 LinoValue::object([
124 ("version", LinoValue::Int(1)),
125 ("created", LinoValue::String("2025-01-01".to_string())),
126 ]),
127 ),
128 ]);
129
130 let encoded = encode(&complex);
131 let decoded = decode(&encoded).unwrap();
132
133 println!(" Encoded: {}", encoded);
134 println!(" Decoded name: {:?}", decoded.get("name"));
135 println!(" Decoded tags: {:?}", decoded.get("tags"));
136 println!(
137 " Decoded metadata.version: {:?}",
138 decoded.get("metadata").and_then(|m| m.get("version"))
139 );
140
141 println!();
142
143 // Example 4: Mixed type array
144 println!("4. Mixed Type Array:");
145
146 let mixed = LinoValue::array([
147 LinoValue::Int(1),
148 LinoValue::String("hello".to_string()),
149 LinoValue::Bool(true),
150 LinoValue::Null,
151 LinoValue::Float(2.5),
152 ]);
153
154 let encoded = encode(&mixed);
155 let decoded = decode(&encoded).unwrap();
156
157 println!(" Encoded: {}", encoded);
158 println!(" Decoded: {:?}", decoded);
159
160 println!();
161
162 // Example 5: Roundtrip verification
163 println!("5. Roundtrip Verification:");
164
165 let data = LinoValue::object([
166 (
167 "users",
168 LinoValue::array([
169 LinoValue::object([
170 ("id", LinoValue::Int(1)),
171 ("name", LinoValue::String("Alice".to_string())),
172 ]),
173 LinoValue::object([
174 ("id", LinoValue::Int(2)),
175 ("name", LinoValue::String("Bob".to_string())),
176 ]),
177 ]),
178 ),
179 ("count", LinoValue::Int(2)),
180 ]);
181
182 let encoded = encode(&data);
183 let decoded = decode(&encoded).unwrap();
184
185 println!(" Original == Decoded: {}", data == decoded);
186
187 println!("\n=== Example completed successfully! ===");
188}Trait Implementations§
Auto Trait Implementations§
impl Freeze for LinoValue
impl RefUnwindSafe for LinoValue
impl Send for LinoValue
impl Sync for LinoValue
impl Unpin for LinoValue
impl UnsafeUnpin for LinoValue
impl UnwindSafe for LinoValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more