Debian Codegraph @

src/keywords/helpers.rs

raw symbols SCIP
1 #![allow(clippy::float_cmp, clippy::cast_sign_loss)]
2
3 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{Maprust-analyzer cargo serde_json 1.0.145 map/Map#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
4
5 use craterust-analyzer cargo jsonschema 0.37.4 crate/::{compilerrust-analyzer cargo jsonschema 0.37.4 compiler/, pathsrust-analyzer cargo jsonschema 0.37.4 paths/::Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, typesrust-analyzer cargo jsonschema 0.37.4 types/::JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#};
6
7 #[inline]
8 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn map_get_u64rust-analyzer cargo jsonschema 0.37.4 keywords/helpers/map_get_u64().<'a>(
9 m: &'a Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>,
10 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
11 type_name: &str,
12 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u64, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>>> {
13 let value = m.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(type_name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
14 match value.as_u64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_u64().() {
15 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(n)),
16 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# if value.is_i64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]is_i64().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::minimumrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]minimum().(
17 Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(),
18 ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(),
19 value,
20 0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
21 ))),
22 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
23 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = value.as_f64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_f64().() {
24 if value.truncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]trunc().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().value {
25 // NOTE: Imprecise cast as big integers are not supported yet
26 #[allow(clippy::cast_possible_truncation)]
27 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value as u64));
28 }
29 }
30 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().(
31 Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(),
32 ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(),
33 value,
34 JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Integerrust-analyzer cargo jsonschema 0.37.4 types/JsonType#Integer#,
35 )))
36 }
37 }
38 }
39
40 /// Fail if the input value is not `u64`.
41 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn fail_on_non_positive_integerrust-analyzer cargo jsonschema 0.37.4 keywords/helpers/fail_on_non_positive_integer().(
42 value: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
43 instance_path: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
44 ) -> ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'_> {
45 if value.is_i64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]is_i64().() {
46 ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::minimumrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]minimum().(Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), instance_path, value, 0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
47 } else {
48 ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().(Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), instance_path, value, JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Integerrust-analyzer cargo jsonschema 0.37.4 types/JsonType#Integer#)
49 }
50 }