Trait argdata::Argdata [−][src]
pub trait Argdata<'d> { fn serialize(
&self,
writer: &mut Write,
fd_map: Option<&mut FdMapping>
) -> Result<()>; fn serialized_length(&self) -> usize; fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError>
where
'd: 'a, { ... } fn get_type(&self) -> Result<Type, ReadError> { ... } fn read_null(&self) -> Result<(), NotRead> { ... } fn read_binary(&self) -> Result<&'d [u8], NotRead> { ... } fn read_bool(&self) -> Result<bool, NotRead> { ... } fn read_encoded_fd<'a>(
&'a self
) -> Result<EncodedFd<&'a ConvertFd>, NotRead>
where
'd: 'a, { ... } fn read_float(&self) -> Result<f64, NotRead> { ... } fn read_int_value(&self) -> Result<IntValue<'d>, NotRead> { ... } fn read_map<'a>(&'a self) -> Result<&'a Map<'d>, NotRead>
where
'd: 'a, { ... } fn read_seq<'a>(&'a self) -> Result<&'a Seq<'d>, NotRead>
where
'd: 'a, { ... } fn read_str_value(&self) -> Result<StrValue<'d>, NotRead> { ... } fn read_timestamp(&self) -> Result<Timespec, NotRead> { ... } }
An argdata value.
Note for implementers of this trait: Although all read methods have provided implementations, they are implemented in terms of eachother. You either need to provide:
- the
read()
method, or - the
get_type()
method and implementations of allread_*()
methods.
Do the latter if read()
would do anything non-trivial, to keep things efficient.
get_type()
and read_*()
need to be consistent, which means that read_$TYPE()
for the type
returned by get_type()
may not return an Err(NotRead::NoFit)
. Otherwise, read()
will
panic.
Required Methods
fn serialize(
&self,
writer: &mut Write,
fd_map: Option<&mut FdMapping>
) -> Result<()>
&self,
writer: &mut Write,
fd_map: Option<&mut FdMapping>
) -> Result<()>
Serialize the argdata to the given writer.
Exactly self.serialized_bytes()
bytes are written to the writer, if no error occurs.
File descriptors are mapped using fd_map
.
If it is None, encoded file descriptors will be kept as is, and actual
file descriptors will be encoded as -1
(invalid).
fn serialized_length(&self) -> usize
The number of bytes that self.serialize()
will write.
Provided Methods
fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError> where
'd: 'a,
'd: 'a,
Read the value.
fn get_type(&self) -> Result<Type, ReadError>
Read the type of the value.
fn read_null(&self) -> Result<(), NotRead>
Check if the value is null.
fn read_binary(&self) -> Result<&'d [u8], NotRead>
Check if the value is a binary blob, and read it if it is.
fn read_bool(&self) -> Result<bool, NotRead>
Check if the value is a boolean, and read it if it is.
fn read_encoded_fd<'a>(&'a self) -> Result<EncodedFd<&'a ConvertFd>, NotRead> where
'd: 'a,
'd: 'a,
Check if the value is a file descriptor, and return it if it is.
Even though this function succeeds (returns an Ok()
), converting the returned EncodedFd
to an Fd
might still fail.
Note: You probably want to use read_fd
instead.
fn read_float(&self) -> Result<f64, NotRead>
Check if the value is a float, and read it if it is.
fn read_int_value(&self) -> Result<IntValue<'d>, NotRead>
Check if the value is an integer, and read it if it is.
Note: You might want to use read_int
instead to
directly get a primitive type like i32
or u64
.
fn read_map<'a>(&'a self) -> Result<&'a Map<'d>, NotRead> where
'd: 'a,
'd: 'a,
Check if the value is a map, and get access to it if it is.
fn read_seq<'a>(&'a self) -> Result<&'a Seq<'d>, NotRead> where
'd: 'a,
'd: 'a,
Check if the value is a seq, and get access to it if it is.
fn read_str_value(&self) -> Result<StrValue<'d>, NotRead>
Check if the value is a string, and read it if it is.
Note: You probably want to use read_str
instead
to directly get a &str
.
fn read_timestamp(&self) -> Result<Timespec, NotRead>
Check if the value is a timestamp, and read it if it is.
Trait Implementations
Implementors
impl<'d, F: ConvertFd> Argdata<'d> for EncodedArgdata<'d, F>
impl<'d> Argdata<'d> for Null
impl<'d> Argdata<'d> for Binary<'d>
impl<'d> Argdata<'d> for Bool
impl<'d> Argdata<'d> for Fd
impl<'d, T: ConvertFd> Argdata<'d> for EncodedFd<T>
impl<'d> Argdata<'d> for InvalidFd
impl<'d> Argdata<'d> for Float
impl<'d> Argdata<'d> for BigInt<'d>
impl<'d, T> Argdata<'d> for Int<T> where
T: Copy,
IntValue<'static>: From<T>,impl<'d, T> Argdata<'d> for Map<'d, T> where
T: MapContainer,
<T as MapContainer>::Key: Argdata<'d>,
<T as MapContainer>::Value: Argdata<'d>,impl<'d, T> Argdata<'d> for Seq<'d, T> where
T: Container,
<T as Container>::Item: Argdata<'d>,impl<'d> Argdata<'d> for Str<'d>
impl<'d> Argdata<'d> for Timestamp