From b5dcdb4474a6ecab2ee50eba2892889ed7e43543 Mon Sep 17 00:00:00 2001 From: Tushar Mathur <tusharmath@gmail.com> 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<A, E, T>: 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<Vec<i32>, (), ()> = Valid::succeed(vec![1, 2]); + /// let v2: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![3, 4]); + /// let result = v1.fuse(v2); + /// assert_eq!(result.to_result().unwrap(), (vec![1, 2], vec![3, 4])); /// ``` fn fuse<A1>(self, other: Valid<A1, E, T>) -> Fusion<(A, A1), E, T> { Fusion(self.zip(other)) @@ -247,7 +247,7 @@ impl<A, E, T> Valid<A, E, T> { /// /// # 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<A, E, T> Valid<A, E, T> { /// /// # 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<A, E, T> Valid<A, E, T> { /// /// # Examples /// ``` - /// use tailcall_valid::Valid; + /// use tailcall_valid::{Valid, Validator}; /// let result = Valid::<i32, (), ()>::succeed(42); /// assert!(result.is_succeed()); /// ``` @@ -291,13 +291,13 @@ impl<A, E, T> Valid<A, E, T> { /// /// # 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::<i32, String, ()>::succeed(n * 2) /// } else { - /// Valid::fail(format!("{} is odd", n)) + /// Valid::<i32, String, ()>::fail(format!("{} is odd", n)) /// } /// }); /// ``` @@ -327,14 +327,14 @@ impl<A, E, T> Valid<A, E, T> { /// /// # 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<i32, &str, ()> = Valid::from_option(some_value, "error"); /// assert_eq!(result, Valid::succeed(42)); /// /// let none_value: Option<i32> = None; - /// let result = Valid::from_option(none_value, "error"); - /// assert_eq!(result, Valid::fail("error")); + /// let result: Valid<i32, &str, ()> = Valid::from_option(none_value, "error"); + /// assert!(result.is_fail()); /// ``` pub fn from_option(option: Option<A>, e: E) -> Valid<A, E, T> { match option { @@ -364,7 +364,7 @@ impl<A, E, T> From<Cause<E, T>> for Valid<A, E, T> { /// /// # 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<A, E, T> From<Vec<Cause<E, T>>> for Valid<A, E, T> { /// /// # 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<A, E, T> Fusion<A, E, T> { /// # 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<Vec<i32>, (), ()> = Valid::succeed(vec![1, 2]); + /// let v2: Valid<Vec<i32>, (), ()> = 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<A1>(self, other: Valid<A1, E, T>) -> Fusion<A::Out, E, T> where @@ -445,7 +446,7 @@ impl<A, E, T> From<Result<A, Cause<E, T>>> for Valid<A, E, T> { /// /// # Examples /// ``` - /// use tailcall_valid::{Valid, Cause}; + /// use tailcall_valid::{Valid, Validator, Cause}; /// let ok_result: Result<i32, Cause<&str, ()>> = Ok(42); /// let valid = Valid::from(ok_result); /// assert_eq!(valid, Valid::succeed(42)); @@ -471,11 +472,11 @@ impl<A, E, T> From<Fusion<A, E, T>> for Valid<A, E, T> { /// # Examples /// ``` /// use tailcall_valid::{Valid, Validator}; - /// let v1 = Valid::succeed(vec![1]); - /// let v2 = Valid::succeed(vec![2]); + /// let v1: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![1]); + /// let v2: Valid<Vec<i32>, (), ()> = Valid::succeed(vec![2]); /// let fusion = v1.fuse(v2); - /// let result: Valid<Vec<i32>, (), ()> = Valid::from(fusion); - /// assert_eq!(result, Valid::succeed(vec![1, 2])); + /// let result: Valid<(Vec<i32>, Vec<i32>), (), ()> = Valid::from(fusion); + /// assert!(result.is_succeed()); /// ``` fn from(value: Fusion<A, E, T>) -> Self { Valid(value.to_result())