Struct glib::value::Value

source ·
#[repr(transparent)]
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.

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 get<'a, T>( &'a self ) -> Result<T, <<T as FromValue<'_>>::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

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>

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
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<'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, Global>> 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<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<Inhibit> for Value

source§

fn from(v: Inhibit) -> 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<NonNull<c_void>> for Value

source§

fn from(v: NonNull<Pointee>) -> 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<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<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, Global>> for Value

source§

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

Converts to this type from the input type.
source§

impl From<Vec<String, Global>> 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<'a> FromValue<'a> for &'a Value

§

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

§

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> ToValue for &'a Value

source§

fn to_value(&self) -> Value

Convert a value to a Value.
source§

fn value_type(&self) -> Type

Returns the type identifer 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 identifer of self. Read more

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Into<Value>,

source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.