pub trait FromFieldValue: Sized {
// Required method
fn from_field_value(
value: FieldValue,
field_name: &str,
) -> SerializationResult<Self>;
}Expand description
Trait for converting FieldValue back to concrete types during deserialization
This trait provides the foundation for automatic type reconstruction during
deserialization. It allows the StructDeserializer to handle different types
generically while ensuring type safety and providing detailed error reporting
for conversion failures.
§Purpose
The FromFieldValue trait enables:
- Generic deserialization: Single interface for all deserializable types
- Type safety: Compile-time guarantees for conversion correctness
- Error handling: Detailed error reporting for conversion failures
- Extensibility: Easy to implement for custom types
- Validation: Runtime type checking and validation
§Required Methods
from_field_value- Convert aFieldValueto the concrete type
§Examples
The trait enables automatic type reconstruction during deserialization with error handling.
§Implementors
Common types that implement this trait include:
- Primitive types:
bool,i8,i16,i32,i64,u8,u16,u32,u64,usize,f32,f64 - String types:
String - Collections:
Vec<T>,HashMap<String, String>,Option<T> - Custom types: Any type implementing
FromFieldValue
§Thread Safety
Implementations should be thread-safe and not modify any shared state during conversion.
Required Methods§
Sourcefn from_field_value(
value: FieldValue,
field_name: &str,
) -> SerializationResult<Self>
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Converts a FieldValue to the concrete type
This method should convert the FieldValue into the implementing type.
If the FieldValue variant doesn’t match the expected type, an error
should be returned with descriptive information including the field name
for debugging purposes.
§Arguments
value- TheFieldValueto convertfield_name- Name of the field being converted (for error reporting)
§Returns
Ok(Self) on successful conversion
Err(SerializationError) if the conversion fails
§Examples
Handles type conversion with proper error reporting and field name context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl FromFieldValue for bool
Converts FieldValue representation back to boolean values
impl FromFieldValue for bool
Converts FieldValue representation back to boolean values
Validates that the FieldValue contains a boolean type and returns the corresponding boolean value with detailed error reporting.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for f32
Converts FieldValue representation back to 32-bit floating point numbers
impl FromFieldValue for f32
Converts FieldValue representation back to 32-bit floating point numbers
Validates that the FieldValue contains an f32 type and returns the corresponding floating point value with precision validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for f64
Converts FieldValue representation back to 64-bit floating point numbers
impl FromFieldValue for f64
Converts FieldValue representation back to 64-bit floating point numbers
Validates that the FieldValue contains an f64 type and returns the corresponding floating point value with precision validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for i8
Converts FieldValue representation back to 8-bit signed integers
impl FromFieldValue for i8
Converts FieldValue representation back to 8-bit signed integers
Validates that the FieldValue contains an i8 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for i16
Converts FieldValue representation back to 16-bit signed integers
impl FromFieldValue for i16
Converts FieldValue representation back to 16-bit signed integers
Validates that the FieldValue contains an i16 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for i32
Converts FieldValue representation back to 32-bit signed integers
impl FromFieldValue for i32
Converts FieldValue representation back to 32-bit signed integers
Validates that the FieldValue contains an i32 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for i64
Converts FieldValue representation back to 64-bit signed integers
impl FromFieldValue for i64
Converts FieldValue representation back to 64-bit signed integers
Validates that the FieldValue contains an i64 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for u8
Converts FieldValue representation back to 8-bit unsigned integers
impl FromFieldValue for u8
Converts FieldValue representation back to 8-bit unsigned integers
Validates that the FieldValue contains a u8 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for u16
Converts FieldValue representation back to 16-bit unsigned integers
impl FromFieldValue for u16
Converts FieldValue representation back to 16-bit unsigned integers
Validates that the FieldValue contains a u16 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for u32
Converts FieldValue representation back to 32-bit unsigned integers
impl FromFieldValue for u32
Converts FieldValue representation back to 32-bit unsigned integers
Validates that the FieldValue contains a u32 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for u64
Converts FieldValue representation back to 64-bit unsigned integers
impl FromFieldValue for u64
Converts FieldValue representation back to 64-bit unsigned integers
Validates that the FieldValue contains a u64 type and returns the corresponding integer value with range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for usize
Converts FieldValue representation back to platform-specific size integers
impl FromFieldValue for usize
Converts FieldValue representation back to platform-specific size integers
Validates that the FieldValue contains a usize type and returns the corresponding integer value with platform-appropriate range validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for String
Converts FieldValue representation back to strings
impl FromFieldValue for String
Converts FieldValue representation back to strings
Validates that the FieldValue contains string data and returns the corresponding string with support for both direct strings and JSON objects.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<bool>
Converts FieldValue representation back to boolean vectors
impl FromFieldValue for Vec<bool>
Converts FieldValue representation back to boolean vectors
Validates that the FieldValue contains an array of boolean values and returns the corresponding vector with logical validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<f32>
Converts FieldValue representation back to single-precision float vectors
impl FromFieldValue for Vec<f32>
Converts FieldValue representation back to single-precision float vectors
Validates that the FieldValue contains an array of f32 values and returns the corresponding vector with indexed error reporting for debugging.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<f64>
Converts FieldValue representation back to double-precision float vectors
impl FromFieldValue for Vec<f64>
Converts FieldValue representation back to double-precision float vectors
Validates that the FieldValue contains an array of f64 values and returns the corresponding vector with precision validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<i32>
Converts FieldValue representation back to integer vectors
impl FromFieldValue for Vec<i32>
Converts FieldValue representation back to integer vectors
Validates that the FieldValue contains an array of integers and returns the corresponding vector with element-by-element validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<u8>
Converts FieldValue representation back to byte vectors
impl FromFieldValue for Vec<u8>
Converts FieldValue representation back to byte vectors
Validates that the FieldValue contains byte data and returns the corresponding byte vector with proper error handling.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<usize>
Converts FieldValue representation back to size vectors
impl FromFieldValue for Vec<usize>
Converts FieldValue representation back to size vectors
Validates that the FieldValue contains an array of size integers and returns the corresponding vector with platform-appropriate validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for Vec<String>
Converts FieldValue representation back to string vectors
impl FromFieldValue for Vec<String>
Converts FieldValue representation back to string vectors
Validates that the FieldValue contains an array of strings and returns the corresponding vector with UTF-8 validation.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl FromFieldValue for HashMap<usize, SerializableParameterState>
impl FromFieldValue for HashMap<usize, SerializableParameterState>
Source§fn from_field_value(
value: FieldValue,
field_name: &str,
) -> SerializationResult<Self>
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Create parameter states HashMap from FieldValue with validation
This method reconstructs the HashMap of parameter states from a FieldValue::Object, performing comprehensive validation and key conversion. It handles the conversion from string keys back to usize tensor IDs while ensuring all parameter state data is properly deserialized and validated.
§Arguments
value- FieldValue containing parameter states data (must be Object variant)field_name- Name of the field being deserialized for error context
§Returns
Reconstructed HashMap<usize, SerializableParameterState> on success, or SerializationError on failure
§Key Conversion Process
- Validation: Ensures FieldValue is Object variant
- Key parsing: Converts string keys back to usize tensor IDs
- State deserialization: Deserializes each parameter state
- Validation: Validates parameter state integrity
- Collection: Builds final HashMap with proper types
§Errors
Returns SerializationError if:
- FieldValue is not Object variant
- Any string key cannot be parsed as usize
- Parameter state deserialization fails
- Invalid parameter state data is encountered
§Performance
- Time Complexity: O(n) where n is the number of parameter states
- Memory Usage: Allocates new HashMap with proper key types
- Validation: Comprehensive key parsing and state validation
Source§impl FromFieldValue for HashMap<String, String>
Converts FieldValue representation back to string hash maps
impl FromFieldValue for HashMap<String, String>
Converts FieldValue representation back to string hash maps
Validates that the FieldValue contains key-value pairs and returns the corresponding hash map with flexible value type conversion.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl<T> FromFieldValue for Option<T>where
T: FromFieldValue,
Converts FieldValue representation back to optional values
impl<T> FromFieldValue for Option<T>where
T: FromFieldValue,
Converts FieldValue representation back to optional values
Validates that the FieldValue contains optional data and returns the corresponding optional value with proper None/Some handling.
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Source§impl<T> FromFieldValue for Vec<T>where
T: StructSerializable,
Converts FieldValue representation back to serializable struct vectors
impl<T> FromFieldValue for Vec<T>where
T: StructSerializable,
Converts FieldValue representation back to serializable struct vectors
Validates that the FieldValue contains an array of struct objects and returns the corresponding vector with struct-by-struct deserialization.