pub struct Object<'a> { /* private fields */ }Expand description
A generic object.
Implementations§
Source§impl<'a> Object<'a>
impl<'a> Object<'a>
Sourcepub fn bool(b: bool) -> Self
pub fn bool(b: bool) -> Self
Create a boolean reference.
§Examples
use gg_sdk::{Object, UnpackedObject};
let obj = Object::bool(false);
assert!(matches!(obj.unpack(), UnpackedObject::Bool(false)));Sourcepub fn buf(buf: &'a str) -> Self
pub fn buf(buf: &'a str) -> Self
Create a string buffer reference.
§Examples
use gg_sdk::{Object, UnpackedObject};
let s = "borrowed";
let obj = Object::buf(s);
assert!(matches!(obj.unpack(), UnpackedObject::Buf("borrowed")));Source§impl<'a> Object<'a>
impl<'a> Object<'a>
Sourcepub fn unpack(&self) -> UnpackedObject<'_>
pub fn unpack(&self) -> UnpackedObject<'_>
Unpack the object to inspect its value.
§Examples
use gg_sdk::{Kv, Object, UnpackedObject};
let obj = Object::i64(42);
match obj.unpack() {
UnpackedObject::Null => println!("null"),
UnpackedObject::Bool(b) => println!("bool: {}", b),
UnpackedObject::I64(n) => assert_eq!(n, 42),
UnpackedObject::F64(f) => println!("float: {}", f),
UnpackedObject::Buf(s) => println!("string: {}", s),
UnpackedObject::List(items) => println!("list of {} items", items.len()),
UnpackedObject::Map(pairs) => println!("map with {} pairs", pairs.len()),
}
let items = [Object::i64(1), Object::buf("two")];
let list = Object::list(&items[..]);
if let UnpackedObject::List(items) = list.unpack() {
assert_eq!(items.len(), 2);
}
let pairs = [Kv::new("key", Object::bool(true))];
let map = Object::map(&pairs[..]);
if let UnpackedObject::Map(pairs) = map.unpack() {
assert_eq!(pairs[0].key(), "key");
}Trait Implementations§
impl<'a> Copy for Object<'a>
Auto Trait Implementations§
impl<'a> Freeze for Object<'a>
impl<'a> RefUnwindSafe for Object<'a>
impl<'a> Send for Object<'a>
impl<'a> Sync for Object<'a>
impl<'a> Unpin for Object<'a>
impl<'a> UnsafeUnpin for Object<'a>
impl<'a> UnwindSafe for Object<'a>
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