1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use crateError;
/// Wraps an infallible closure so it can be used where a fallible one is expected.
///
/// This avoids the need to write `Ok::<_, std::convert::Infallible>(...)` in
/// encoder/codec closures that cannot fail.
///
/// # Examples
///
/// ```
/// use cachet::{infallible, TransformCodec};
///
/// // Mixed fallibility: encode is fallible, decode is infallible
/// let codec = TransformCodec::new(
/// |v: &String| v.parse::<i32>(),
/// infallible(|v: &i32| v.to_string()),
/// );
/// ```
+ Send + Sync + 'static
where
F: Fn + Send + Sync + 'static,
/// A one-directional encoder that converts values from type `From` to type `To`.
///
/// Used for key encoding in the transform builder pipeline, where
/// only the forward direction is needed.
/// A bidirectional codec that converts between types `A` and `B`.
///
/// Extends [`Encoder<A, B>`] with a `decode` method for the reverse direction.
/// Used for value encoding and decoding in the transform builder pipeline.