Skip to main content

Object

Struct Object 

Source
pub struct Object<'a> { /* private fields */ }
Expand description

A generic object.

Implementations§

Source§

impl<'a> Object<'a>

Source

pub const NULL: Self

Null object constant.

Source

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)));
Source

pub fn i64(i: i64) -> Self

Create a signed integer reference.

Source

pub fn f64(f: f64) -> Self

Create a floating point reference.

Source

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

pub fn list(list: &'a [Object<'a>]) -> Self

Create a list reference.

§Examples
use gg_sdk::{Object, UnpackedObject};

let items = [Object::i64(1), Object::i64(2)];
let obj = Object::list(&items[..]);
if let UnpackedObject::List(list) = obj.unpack() {
    assert_eq!(list.len(), 2);
}
Source

pub fn map(map: &'a [Kv<'a>]) -> Self

Create a map reference.

§Examples
use gg_sdk::{Kv, Object, UnpackedObject};

let pairs = [Kv::new("k", Object::i64(1))];
let obj = Object::map(&pairs[..]);
if let UnpackedObject::Map(m) = obj.unpack() {
    assert_eq!(m.len(), 1);
}
Source§

impl<'a> Object<'a>

Source

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§

Source§

impl<'a> Clone for Object<'a>

Source§

fn clone(&self) -> Object<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Object<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Object<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a [Kv<'a>]> for Object<'a>

Source§

fn from(map: &'a [Kv<'a>]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a [Object<'a>]> for Object<'a>

Source§

fn from(list: &'a [Object<'a>]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Object<'a>

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<List<'a>> for Object<'a>

Source§

fn from(list: List<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Map<'a>> for Object<'a>

Source§

fn from(map: Map<'a>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Object<'_>

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Object<'_>

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Object<'_>

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.