From b5dcdb4474a6ecab2ee50eba2892889ed7e43543 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Sat, 14 Dec 2024 22:36:49 -0800 Subject: [PATCH] doc: fix rust docs --- src/valid.rs | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/valid.rs b/src/valid.rs index aa5b0c3..8561ab7 100644 --- a/src/valid.rs +++ b/src/valid.rs @@ -103,10 +103,10 @@ pub trait Validator: Sized { /// # Examples /// ``` /// use tailcall_valid::{Valid, Validator}; - /// let v1 = Valid::succeed(vec![1]); - /// let v2 = Valid::succeed(vec![2]); - /// let result = v1.fuse(v2).to_result().unwrap(); - /// assert_eq!(result, vec![1, 2]); + /// let v1: Valid, (), ()> = Valid::succeed(vec![1, 2]); + /// let v2: Valid, (), ()> = Valid::succeed(vec![3, 4]); + /// let result = v1.fuse(v2); + /// assert_eq!(result.to_result().unwrap(), (vec![1, 2], vec![3, 4])); /// ``` fn fuse(self, other: Valid) -> Fusion<(A, A1), E, T> { Fusion(self.zip(other)) @@ -247,7 +247,7 @@ impl Valid { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let result: Valid<(), i32, ()> = Valid::fail(1); /// assert!(result.is_fail()); /// ``` @@ -262,7 +262,7 @@ impl Valid { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let result = Valid::<(), &str, &str>::fail_at("error", "context"); /// assert!(result.is_fail()); /// ``` @@ -278,7 +278,7 @@ impl Valid { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let result = Valid::::succeed(42); /// assert!(result.is_succeed()); /// ``` @@ -291,13 +291,13 @@ impl Valid { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let numbers = vec![1, 2, 3]; /// let result = Valid::from_iter(numbers, |n| { /// if n % 2 == 0 { - /// Valid::succeed(n * 2) + /// Valid::::succeed(n * 2) /// } else { - /// Valid::fail(format!("{} is odd", n)) + /// Valid::::fail(format!("{} is odd", n)) /// } /// }); /// ``` @@ -327,14 +327,14 @@ impl Valid { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let some_value = Some(42); - /// let result = Valid::from_option(some_value, "error"); + /// let result: Valid = Valid::from_option(some_value, "error"); /// assert_eq!(result, Valid::succeed(42)); /// /// let none_value: Option = None; - /// let result = Valid::from_option(none_value, "error"); - /// assert_eq!(result, Valid::fail("error")); + /// let result: Valid = Valid::from_option(none_value, "error"); + /// assert!(result.is_fail()); /// ``` pub fn from_option(option: Option, e: E) -> Valid { match option { @@ -364,7 +364,7 @@ impl From> for Valid { /// /// # Examples /// ``` - /// use tailcall_valid::{Valid, Cause}; + /// use tailcall_valid::{Valid, Validator, Cause}; /// let cause = Cause::new("error"); /// let result: Valid<(), &str, ()> = Valid::from(cause); /// assert!(result.is_fail()); @@ -379,7 +379,7 @@ impl From>> for Valid { /// /// # Examples /// ``` - /// use tailcall_valid::{Valid, Cause}; + /// use tailcall_valid::{Valid, Validator, Cause}; /// let causes = vec![Cause::new("error1"), Cause::new("error2")]; /// let result: Valid<(), &str, ()> = Valid::from(causes); /// assert!(result.is_fail()); @@ -415,10 +415,11 @@ impl Fusion { /// # Examples /// ``` /// use tailcall_valid::{Valid, Validator}; - /// let v1 = Valid::succeed(vec![1, 2]); - /// let v2 = Valid::succeed(vec![3, 4]); - /// let result = v1.fuse(v2).to_result().unwrap(); - /// assert_eq!(result, vec![1, 2, 3, 4]); + /// let v1: Valid, (), ()> = Valid::succeed(vec![1, 2]); + /// let v2: Valid, (), ()> = Valid::succeed(vec![3, 4]); + /// let fusion = v1.fuse(v2); + /// let result = fusion.to_result().unwrap(); + /// assert_eq!(result, (vec![1, 2], vec![3, 4])); /// ``` pub fn fuse(self, other: Valid) -> Fusion where @@ -445,7 +446,7 @@ impl From>> for Valid { /// /// # Examples /// ``` - /// use tailcall_valid::{Valid, Cause}; + /// use tailcall_valid::{Valid, Validator, Cause}; /// let ok_result: Result> = Ok(42); /// let valid = Valid::from(ok_result); /// assert_eq!(valid, Valid::succeed(42)); @@ -471,11 +472,11 @@ impl From> for Valid { /// # Examples /// ``` /// use tailcall_valid::{Valid, Validator}; - /// let v1 = Valid::succeed(vec![1]); - /// let v2 = Valid::succeed(vec![2]); + /// let v1: Valid, (), ()> = Valid::succeed(vec![1]); + /// let v2: Valid, (), ()> = Valid::succeed(vec![2]); /// let fusion = v1.fuse(v2); - /// let result: Valid, (), ()> = Valid::from(fusion); - /// assert_eq!(result, Valid::succeed(vec![1, 2])); + /// let result: Valid<(Vec, Vec), (), ()> = Valid::from(fusion); + /// assert!(result.is_succeed()); /// ``` fn from(value: Fusion) -> Self { Valid(value.to_result())