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.
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
impl Value
sourcepub fn from_type(type_: Type) -> Self
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.
sourcepub unsafe fn from_type_unchecked(type_: Type) -> Self
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 Value
s.
sourcepub fn for_value_type<T: ValueType>() -> Self
pub fn for_value_type<T: ValueType>() -> Self
Creates a new Value
that is initialized for a given ValueType
.
sourcepub fn from_static_str(s: &'static GStr) -> Self
pub fn from_static_str(s: &'static GStr) -> Self
Creates a new String
-typed Value
from a 'static
string.
sourcepub fn from_interned_str(s: &'static GStr) -> Self
Available on crate feature v2_66
only.
pub fn from_interned_str(s: &'static GStr) -> Self
v2_66
only.Creates a new String
-typed Value
from a 'static
string that is also assumed to be
interned.
sourcepub fn get<'a, T>(
&'a self,
) -> Result<T, <<T as FromValue<'_>>::Checker as ValueTypeChecker>::Error>where
T: FromValue<'a>,
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.
sourcepub fn get_owned<T>(
&self,
) -> Result<T, <<T as FromValue<'_>>::Checker as ValueTypeChecker>::Error>where
T: for<'b> FromValue<'b> + 'static,
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
.
sourcepub fn is<T: StaticType>(&self) -> bool
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
.
sourcepub fn is_type(&self, type_: Type) -> bool
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_
.
sourcepub fn type_transformable(src: Type, dst: Type) -> bool
pub fn type_transformable(src: Type, dst: Type) -> bool
Returns whether Value
s 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.
way.
On Unix, this is guaranteed to be in the same format waitpid() returns,
and on Windows it is guaranteed to be the result of GetExitCodeProcess().
Prior to the introduction of this function in GLib 2.34, interpreting @wait_status required use of platform-specific APIs, which is problematic for software using GLib as a cross-platform layer.
Additionally, many programs simply want to determine whether or not the child exited successfully, and either propagate a #GError or print a message to standard error. In that common case, this function can be used. Note that the error message in @error will contain human-readable information about the wait status.
The @domain and @code of @error have special semantics in the case where the process has an “exit code”, as opposed to being killed by a signal. On Unix, this happens if WIFEXITED() would be true of @wait_status. On Windows, it is always the case.
The special semantics are that the actual exit code will be the
code set in @error, and the domain will be G_SPAWN_EXIT_ERROR
.
This allows you to differentiate between different exit codes.
If the process was terminated by some means other than an exit
status (for example if it was killed by a signal), the domain will be
G_SPAWN_ERROR
and the code will be G_SPAWN_ERROR_FAILED
.
This function just offers convenience; you can of course also check
the available platform via a macro such as G_OS_UNIX
, and use
WIFEXITED() and WEXITSTATUS() on @wait_status directly. Do not attempt
to scan or parse the error message string; it may be translated and/or
change in future versions of GLib.
Prior to version 2.70, g_spawn_check_exit_status() provides the same functionality, although under a misleading name.
§wait_status
A platform-specific wait status as returned from g_spawn_sync()
§Returns
true
if child exited successfully, false
otherwise (and
@error will be set)
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.
way.
On Unix, this is guaranteed to be in the same format waitpid() returns,
and on Windows it is guaranteed to be the result of GetExitCodeProcess().
Prior to the introduction of this function in GLib 2.34, interpreting @wait_status required use of platform-specific APIs, which is problematic for software using GLib as a cross-platform layer.
Additionally, many programs simply want to determine whether or not the child exited successfully, and either propagate a #GError or print a message to standard error. In that common case, this function can be used. Note that the error message in @error will contain human-readable information about the wait status.
The @domain and @code of @error have special semantics in the case where the process has an “exit code”, as opposed to being killed by a signal. On Unix, this happens if WIFEXITED() would be true of @wait_status. On Windows, it is always the case.
The special semantics are that the actual exit code will be the
code set in @error, and the domain will be G_SPAWN_EXIT_ERROR
.
This allows you to differentiate between different exit codes.
If the process was terminated by some means other than an exit
status (for example if it was killed by a signal), the domain will be
G_SPAWN_ERROR
and the code will be G_SPAWN_ERROR_FAILED
.
This function just offers convenience; you can of course also check
the available platform via a macro such as G_OS_UNIX
, and use
WIFEXITED() and WEXITSTATUS() on @wait_status directly. Do not attempt
to scan or parse the error message string; it may be translated and/or
change in future versions of GLib.
Prior to version 2.70, g_spawn_check_exit_status() provides the same functionality, although under a misleading name.
§wait_status
A platform-specific wait status as returned from g_spawn_sync()
§Returns
true
if child exited successfully, false
otherwise (and
@error will be set)
sourcepub fn transform<T: ValueType>(&self) -> Result<Value, BoolError>
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.
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.
sourcepub fn transform_with_type(&self, type_: Type) -> Result<Value, BoolError>
pub fn transform_with_type(&self, type_: Type) -> Result<Value, BoolError>
Tries to transform the value into a value of the target type
sourcepub fn try_into_send_value<T: Send + StaticType>(
self,
) -> Result<SendValue, Self>
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.
sourcepub unsafe fn into_send_value(self) -> SendValue
pub unsafe fn into_send_value(self) -> SendValue
Trait Implementations§
source§impl Extend<Value> for ValueArray
impl Extend<Value> for ValueArray
source§fn extend<T: IntoIterator<Item = Value>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Value>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl From<BindingFlags> for Value
impl From<BindingFlags> for Value
source§fn from(v: BindingFlags) -> Self
fn from(v: BindingFlags) -> Self
source§impl From<BoxedValue> for Value
impl From<BoxedValue> for Value
source§fn from(v: BoxedValue) -> Self
fn from(v: BoxedValue) -> Self
source§impl From<ControlFlow> for Value
impl From<ControlFlow> for Value
source§fn from(v: ControlFlow) -> Self
fn from(v: ControlFlow) -> Self
source§impl From<IOCondition> for Value
impl From<IOCondition> for Value
source§fn from(v: IOCondition) -> Self
fn from(v: IOCondition) -> Self
source§impl From<MainContext> for Value
impl From<MainContext> for Value
source§fn from(s: MainContext) -> Self
fn from(s: MainContext) -> Self
source§impl From<MarkupParseContext> for Value
impl From<MarkupParseContext> for Value
source§fn from(s: MarkupParseContext) -> Self
fn from(s: MarkupParseContext) -> Self
source§impl From<NonZero<i32>> for Value
impl From<NonZero<i32>> for Value
source§fn from(v: NonZeroI32) -> Self
fn from(v: NonZeroI32) -> Self
source§impl From<NonZero<i64>> for Value
impl From<NonZero<i64>> for Value
source§fn from(v: NonZeroI64) -> Self
fn from(v: NonZeroI64) -> Self
source§impl From<NonZero<u32>> for Value
impl From<NonZero<u32>> for Value
source§fn from(v: NonZeroU32) -> Self
fn from(v: NonZeroU32) -> Self
source§impl From<NonZero<u64>> for Value
impl From<NonZero<u64>> for Value
source§fn from(v: NonZeroU64) -> Self
fn from(v: NonZeroU64) -> Self
source§impl From<NormalizeMode> for Value
impl From<NormalizeMode> for Value
source§fn from(v: NormalizeMode) -> Self
fn from(v: NormalizeMode) -> Self
source§impl From<Propagation> for Value
impl From<Propagation> for Value
source§fn from(v: Propagation) -> Self
fn from(v: Propagation) -> Self
source§impl From<UnicodeBreakType> for Value
impl From<UnicodeBreakType> for Value
source§fn from(v: UnicodeBreakType) -> Self
fn from(v: UnicodeBreakType) -> Self
source§impl From<UnicodeScript> for Value
impl From<UnicodeScript> for Value
source§fn from(v: UnicodeScript) -> Self
fn from(v: UnicodeScript) -> Self
source§impl From<UnicodeType> for Value
impl From<UnicodeType> for Value
source§fn from(v: UnicodeType) -> Self
fn from(v: UnicodeType) -> Self
source§impl From<ValueArray> for Value
impl From<ValueArray> for Value
source§fn from(o: ValueArray) -> Self
fn from(o: ValueArray) -> Self
source§impl From<VariantDict> for Value
impl From<VariantDict> for Value
source§fn from(s: VariantDict) -> Self
fn from(s: VariantDict) -> Self
source§impl FromIterator<Value> for ValueArray
impl FromIterator<Value> for ValueArray
source§impl<'a> FromValue<'a> for &'a Value
impl<'a> FromValue<'a> for &'a Value
source§type Checker = NopChecker
type Checker = NopChecker
source§unsafe fn from_value(value: &'a Value) -> Self
unsafe fn from_value(value: &'a Value) -> Self
Value
. Read moresource§impl<'a> FromValue<'a> for Value
impl<'a> FromValue<'a> for Value
source§type Checker = NopChecker
type Checker = NopChecker
source§unsafe fn from_value(value: &'a Value) -> Self
unsafe fn from_value(value: &'a Value) -> Self
Value
. Read moreAuto 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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)