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
54
55
56
57
58
59
60
61
62
63
//! This module provides examples of what the [`wrap`] macro generates.
//!
//! [`SimpleWrapper`] is generated with the following code:
//! ```
//! # #[macro_use] extern crate sophia_iri;
//! wrap! { SimpleWrapper<T: PartialEq<isize>> :
//! /// SimpleWrapper wraps any type comparable to `isize`,
//! /// and guarantees that the wrapped value is not equal to 0.
//! #[allow(dead_code)]
//! pub fn new(inner: T) -> Result<Self, String> {
//! if inner != 0 {
//! Ok(Self(inner))
//! } else {
//! Err("inner is equal to zero".into())
//! }
//! }
//!}
//! ```
//!
//! [`BorrowingWrapper`] is generated with the following code:
//! ```
//! # #[macro_use] extern crate sophia_iri;
//! wrap! { BorrowingWrapper borrowing str :
//! /// BorrowingWrapper wraps any `Borrow<str>` type,
//! /// and guarantees that the wrapped value contains `"hello"`.
//! #[allow(dead_code)]
//! pub fn new(inner: T) -> Result<Self, String> {
//! if inner.borrow().contains("hello") {
//! Ok(Self(inner))
//! } else {
//! Err("inner does not contain 'hello'".into())
//! }
//! }
//! }
//! ```
//! As can be seen, this second form generates more methods and trait implementations than the previous one.
use cratewrap;
wrap!
wrap!