Debian Codegraph @

tests/integration/from_into.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#;
2
3 use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*;
4
5 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
6 #[serde(into = "String", try_from = "String")]
7 #[schemars(extend("pattern" = r"^[0-9a-f]{16}:[0-9a-f]{16}:[0-9a-f]{4}$"))]
8 pub struct EventSequenceNumberrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber# {
9 transaction_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#transaction_id.: u64,
10 statement_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#statement_id.: u64,
11 write_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#write_id.: u16,
12 }
13
14 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<EventSequenceNumberrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#> for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
15 fn fromrust-analyzer cargo schemars 1.2.2 from_into/impl#[String][`From<EventSequenceNumber>`]from().(value: EventSequenceNumberrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#) -> Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[String][`From<EventSequenceNumber>`] {
16 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
17 "{:016x}:{:016x}:{:04x}",
18 value.transaction_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#transaction_id., value.statement_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#statement_id., value.write_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#write_id.
19 )
20 }
21 }
22
23 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for EventSequenceNumberrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber# {
24 type Errorrust-analyzer cargo schemars 1.2.2 from_into/impl#[EventSequenceNumber][`TryFrom<String>`]Error# = ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#;
25
26 fn try_fromrust-analyzer cargo schemars 1.2.2 from_into/impl#[EventSequenceNumber][`TryFrom<String>`]try_from().(value: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[EventSequenceNumber][`TryFrom<String>`], Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[EventSequenceNumber][`TryFrom<String>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> {
27 let mut parts = value.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(':');
28 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[EventSequenceNumber][`TryFrom<String>`] {
29 transaction_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#transaction_id.: parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
30 statement_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#statement_id.: parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
31 write_idrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#write_id.: parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
32 })
33 }
34 }
35
36 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
37 fn into_and_try_fromrust-analyzer cargo schemars 1.2.2 from_into/into_and_try_from().() {
38 testrust-analyzer cargo schemars 1.2.2 test!!(EventSequenceNumberrust-analyzer cargo schemars 1.2.2 from_into/EventSequenceNumber#)
39 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
40 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
41 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
42 }
43
44 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
45 #[serde(from = "i128")]
46 struct ClampingI8rust-analyzer cargo schemars 1.2.2 from_into/ClampingI8#(i8);
47
48 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<i128> for ClampingI8rust-analyzer cargo schemars 1.2.2 from_into/ClampingI8# {
49 fn fromrust-analyzer cargo schemars 1.2.2 from_into/impl#[ClampingI8][`From<i128>`]from().(value: i128) -> Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[ClampingI8][`From<i128>`] {
50 Selfrust-analyzer cargo schemars 1.2.2 from_into/impl#[ClampingI8][`From<i128>`](if value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]gt().i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX. as i128 {
51 i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX.
52 } else if value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i128][`PartialOrd<Self>`]lt().i8::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MIN. as i128 {
53 i8::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MIN.
54 } else {
55 value as i8
56 })
57 }
58 }
59
60 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
61 fn fromrust-analyzer cargo schemars 1.2.2 from_into/from().() {
62 testrust-analyzer cargo schemars 1.2.2 test!!(ClampingI8rust-analyzer cargo schemars 1.2.2 from_into/ClampingI8#)
63 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
64 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
65 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
66 }