glib::value

Struct Value

Source
pub struct Value { /* private fields */ }
Expand description

A generic value capable of carrying various types.

Once created the type of the value can’t be changed.

Some types (e.g. String and objects) support None values while others (e.g. numeric types) don’t.

Value does not implement the Send trait, but SendValue can be used instead.

See the module documentation for more details. An opaque structure used to hold different types of values.

The data within the structure has protected scope: it is accessible only to functions within a TypeValueTable structure, or implementations of the g_value_*() API. That is, code portions which implement new fundamental types.

Value users cannot make any assumptions about how data is stored within the 2 element data union, and the g_type member should only be accessed through the G_VALUE_TYPE() macro.

GLib type: Inline allocated boxed type with stack copy semantics.

Implementations§

Source§

impl Value

Source

pub fn as_ptr(&self) -> *mut GValue

Source

pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const GValue) -> &'a Self

Borrows the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut GValue) -> &'a mut Self

Borrows the underlying C value mutably.

Source§

impl Value

Source

pub fn from_type(type_: Type) -> Self

Creates a new Value that is initialized with type_.

§Panics

If type_ can’t be stored in a Value this function panics.

Source

pub unsafe fn from_type_unchecked(type_: Type) -> Self

Creates a new Value that is initialized with type_.

§SAFETY

This must be called with a valid type_ that can be stored in Values.

Source

pub fn for_value_type<T: ValueType>() -> Self

Creates a new Value that is initialized for a given ValueType.

Source

pub fn from_static_str(s: &'static GStr) -> Self

Creates a new String-typed Value from a 'static string.

Source

pub fn from_interned_str(s: &'static GStr) -> Self

Available on crate feature v2_66 only.

Creates a new String-typed Value from a 'static string that is also assumed to be interned.

Source

pub fn get<'a, T>( &'a self, ) -> Result<T, <<T as FromValue<'a>>::Checker as ValueTypeChecker>::Error>
where T: FromValue<'a>,

Tries to get a value of type T.

Returns Ok if the type is correct.

Source

pub fn get_owned<T>( &self, ) -> Result<T, <<T as FromValue<'_>>::Checker as ValueTypeChecker>::Error>
where T: for<'b> FromValue<'b> + 'static,

Tries to get a value of an owned type T.

Source

pub fn is<T: StaticType>(&self) -> bool

Returns true if the type of the value corresponds to T or is a sub-type of T.

Source

pub fn is_type(&self, type_: Type) -> bool

Returns true if the type of the value corresponds to type_ or is a sub-type of type_.

Source

pub fn type_(&self) -> Type

Returns the type of the value.

Source

pub fn type_transformable(src: Type, dst: Type) -> bool

Returns whether Values of type src can be transformed to type dst. Check whether transform() is able to transform values of type src_type into values of type dest_type. Note that for the types to be transformable, they must be compatible or a transformation function must be registered.

§src_type

Source type.

§dest_type

Target type.

§Returns

true if the transformation is possible, false otherwise.

Source

pub fn transform<T: ValueType>(&self) -> Result<Value, BoolError>

Tries to transform the value into a value of the target type Tries to cast the contents of self into a type appropriate to store in dest_value, e.g. to transform a G_TYPE_INT value into a G_TYPE_FLOAT value. Performing transformations between value types might incur precision lossage. Especially transformations into strings might reveal seemingly arbitrary results and shouldn’t be relied upon for production code (such as rcfile value or object property serialization).

§dest_value

Target value.

§Returns

Whether a transformation rule was found and could be applied. Upon failing transformations, dest_value is left untouched.

Source

pub fn transform_with_type(&self, type_: Type) -> Result<Value, BoolError>

Tries to transform the value into a value of the target type

Source

pub fn into_raw(self) -> GValue

Consumes Value and returns the corresponding GValue.

Source

pub fn try_into_send_value<T: Send + StaticType>( self, ) -> Result<SendValue, Self>

Converts a Value into a SendValue. This fails if self does not store a value of type T. It is required for T to be Send to call this function.

Source

pub unsafe fn into_send_value(self) -> SendValue

Converts a Value into a SendValue.

§Safety

The type of the value contained in self must be Send.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Copies the inline boxed type by value with the type-specific copy function.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Extend<Value> for ValueArray

Source§

fn extend<T: IntoIterator<Item = Value>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, T: ?Sized + ToValue> From<&'a T> for Value

Source§

fn from(value: &'a T) -> Self

Converts to this type from the input type.
Source§

impl From<*mut c_void> for Value

Source§

fn from(v: Pointer) -> Self

Converts to this type from the input type.
Source§

impl From<BindingFlags> for Value

Source§

fn from(v: BindingFlags) -> Self

Converts to this type from the input type.
Source§

impl From<Box<str>> for Value

Source§

fn from(s: Box<str>) -> Self

Converts to this type from the input type.
Source§

impl From<BoxedValue> for Value

Source§

fn from(v: BoxedValue) -> Self

Converts to this type from the input type.
Source§

impl From<ByteArray> for Value

Source§

fn from(s: ByteArray) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(s: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Checksum> for Value

Source§

fn from(o: Checksum) -> Self

Converts to this type from the input type.
Source§

impl From<Closure> for Value

Source§

fn from(s: Closure) -> Self

Converts to this type from the input type.
Source§

impl From<ControlFlow> for Value

Source§

fn from(v: ControlFlow) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for Value

Source§

fn from(s: DateTime) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Value

Source§

fn from(o: Error) -> Self

Converts to this type from the input type.
Source§

impl From<GString> for Value

Source§

fn from(s: GString) -> Self

Converts to this type from the input type.
Source§

impl From<ILong> for Value

Source§

fn from(v: ILong) -> Self

Converts to this type from the input type.
Source§

impl From<IOCondition> for Value

Source§

fn from(v: IOCondition) -> Self

Converts to this type from the input type.
Source§

impl From<KeyFile> for Value

Source§

fn from(s: KeyFile) -> Self

Converts to this type from the input type.
Source§

impl From<MainContext> for Value

Source§

fn from(s: MainContext) -> Self

Converts to this type from the input type.
Source§

impl From<MainLoop> for Value

Source§

fn from(s: MainLoop) -> Self

Converts to this type from the input type.
Source§

impl From<MarkupParseContext> for Value

Source§

fn from(s: MarkupParseContext) -> Self

Converts to this type from the input type.
Source§

impl From<MatchInfo<'static>> for Value

Source§

fn from(s: MatchInfo<'static>) -> Self

Converts to this type from the input type.
Source§

impl From<NonNull<c_void>> for Value

Source§

fn from(v: NonNull<Pointee>) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<i32>> for Value

Source§

fn from(v: NonZeroI32) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<i64>> for Value

Source§

fn from(v: NonZeroI64) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<i8>> for Value

Source§

fn from(v: NonZeroI8) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<u32>> for Value

Source§

fn from(v: NonZeroU32) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<u64>> for Value

Source§

fn from(v: NonZeroU64) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<u8>> for Value

Source§

fn from(v: NonZeroU8) -> Self

Converts to this type from the input type.
Source§

impl From<NormalizeMode> for Value

Source§

fn from(v: NormalizeMode) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value> + ToValueOptional> From<Option<T>> for Value

Source§

fn from(t: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<PathBuf> for Value

Source§

fn from(s: PathBuf) -> Self

Converts to this type from the input type.
Source§

impl From<Propagation> for Value

Source§

fn from(v: Propagation) -> Self

Converts to this type from the input type.
Source§

impl From<Regex> for Value

Source§

fn from(s: Regex) -> Self

Converts to this type from the input type.
Source§

impl From<SendValue> for Value

Source§

fn from(value: SendValue) -> Self

Converts to this type from the input type.
Source§

impl From<Source> for Value

Source§

fn from(s: Source) -> Self

Converts to this type from the input type.
Source§

impl From<StrV> for Value

Source§

fn from(s: StrV) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<TimeZone> for Value

Source§

fn from(s: TimeZone) -> Self

Converts to this type from the input type.
Source§

impl From<ULong> for Value

Source§

fn from(v: ULong) -> Self

Converts to this type from the input type.
Source§

impl From<UnicodeBreakType> for Value

Source§

fn from(v: UnicodeBreakType) -> Self

Converts to this type from the input type.
Source§

impl From<UnicodeScript> for Value

Source§

fn from(v: UnicodeScript) -> Self

Converts to this type from the input type.
Source§

impl From<UnicodeType> for Value

Source§

fn from(v: UnicodeType) -> Self

Converts to this type from the input type.
Source§

impl From<Uri> for Value

Available on crate feature v2_66 only.
Source§

fn from(s: Uri) -> Self

Converts to this type from the input type.
Source§

impl From<ValueArray> for Value

Source§

fn from(o: ValueArray) -> Self

Converts to this type from the input type.
Source§

impl From<VariantDict> for Value

Source§

fn from(s: VariantDict) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<GString>> for Value

Source§

fn from(v: Vec<GString>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<String>> for Value

Source§

fn from(s: Vec<String>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Value

Source§

fn from(v: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Value> for ValueArray

Source§

fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> FromValue<'a> for &'a Value

Source§

type Checker = NopChecker

Value type checker.
Source§

unsafe fn from_value(value: &'a Value) -> Self

Get the contained value from a Value. Read more
Source§

impl<'a> FromValue<'a> for Value

Source§

type Checker = NopChecker

Value type checker.
Source§

unsafe fn from_value(value: &'a Value) -> Self

Get the contained value from a Value. Read more
Source§

impl ToValue for &Value

Source§

fn to_value(&self) -> Value

Convert a value to a Value.
Source§

fn value_type(&self) -> Type

Returns the type identifier of self. Read more
Source§

impl ToValue for Value

Source§

fn to_value(&self) -> Value

Convert a value to a Value.
Source§

fn value_type(&self) -> Type

Returns the type identifier of self. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

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, dst: *mut T)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

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> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.