Debian Codegraph @

third_party/rust/rmp/src/encode/dec.rs

raw
1 use super::{write_marker, RmpWrite};
2 use crate::encode::ValueWriteError;
3 use crate::Marker;
4
5 /// Encodes and attempts to write an `f32` value as a 5-byte sequence into the given write.
6 ///
7 /// The first byte becomes the `f32` marker and the others will represent the data itself.
8 ///
9 /// # Errors
10 ///
11 /// This function will return `ValueWriteError` on any I/O error occurred while writing either the
12 /// marker or the data.
13 pub fn write_f32<W: RmpWrite>(wr: &mut W, val: f32) -> Result<(), ValueWriteError<W::Error>> {
14 write_marker(wr, Marker::F32)?;
15 wr.write_data_f32(val)?;
16 Ok(())
17 }
18
19 /// Encodes and attempts to write an `f64` value as a 9-byte sequence into the given write.
20 ///
21 /// The first byte becomes the `f64` marker and the others will represent the data itself.
22 ///
23 /// # Errors
24 ///
25 /// This function will return `ValueWriteError` on any I/O error occurred while writing either the
26 /// marker or the data.
27 pub fn write_f64<W: RmpWrite>(wr: &mut W, val: f64) -> Result<(), ValueWriteError<W::Error>> {
28 write_marker(wr, Marker::F64)?;
29 wr.write_data_f64(val)?;
30 Ok(())
31 }