Skip to content

Commit

Permalink
doc: fix rust docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Dec 15, 2024
1 parent 77f8f30 commit b5dcdb4
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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());
/// ```
Expand All @@ -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());
/// ```
Expand All @@ -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());
/// ```
Expand All @@ -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))
/// }
/// });
/// ```
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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())
Expand Down

0 comments on commit b5dcdb4

Please sign in to comment.