Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/bufany.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,21 @@ impl<'a> Bufany<'a> {
/// ## Example
///
/// ```
/// use anybuf::{Anybuf, Bufany};
/// use anybuf::{Anybuf, Bufany, RepeatedStringError};
///
/// let serialized = Anybuf::new()
/// .append_uint64(1, 150)
/// .append_bytes(2, vec![0xF0, 0x00])
/// .append_repeated_string(3, &["valid utf8 string", "hello"])
/// .into_vec();
/// let decoded = Bufany::deserialize(&serialized).unwrap();
/// assert_eq!(decoded.repeated_string(3).unwrap(), ["valid utf8 string".to_string(), "hello".to_string()]);
///
/// // happy path
/// let strings = decoded.repeated_string(3).unwrap();
/// assert_eq!(strings, ["valid utf8 string".to_string(), "hello".to_string()]);
///
/// // cannot get strings from int field
/// assert!(matches!(decoded.repeated_string(1).unwrap_err(), RepeatedStringError::TypeMismatch));
/// ```
pub fn repeated_string(&self, field_number: u32) -> Result<Vec<String>, RepeatedStringError> {
let values = self.repeated_value_ref(field_number);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ mod slice_reader;
mod varint;

pub use crate::anybuf::Anybuf;
pub use crate::bufany::{Bufany, BufanyError};
pub use crate::bufany::{Bufany, BufanyError, RepeatedStringError};
Loading