From a056839aae69145e9914fd71a8ccef46a57d911a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Dec 2024 00:01:42 +0100 Subject: [PATCH 1/2] Add missing RepeatedStringError to public API --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5f6bce8..fb24809 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; From dfc6997bbffaa020a56cd2dba7f1063118d9e9c5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Dec 2024 12:16:15 +0100 Subject: [PATCH 2/2] Test RepeatedStringError in example --- src/bufany.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bufany.rs b/src/bufany.rs index b499070..cb51e28 100644 --- a/src/bufany.rs +++ b/src/bufany.rs @@ -716,7 +716,7 @@ impl<'a> Bufany<'a> { /// ## Example /// /// ``` - /// use anybuf::{Anybuf, Bufany}; + /// use anybuf::{Anybuf, Bufany, RepeatedStringError}; /// /// let serialized = Anybuf::new() /// .append_uint64(1, 150) @@ -724,7 +724,13 @@ impl<'a> Bufany<'a> { /// .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, RepeatedStringError> { let values = self.repeated_value_ref(field_number);