Skip to main content

InstanceId

Struct InstanceId 

Source
pub struct InstanceId(/* private fields */);
Expand description

An arbitrary-precision instance identifier as written by #42.

The Part 21 grammar does not impose a machine-integer bound, so the decimal digits are retained lexically.

Implementations§

Source§

impl InstanceId

Source

pub fn new(value: &str) -> Option<Self>

Creates an identifier from non-empty ASCII decimal digits.

Source

pub fn as_str(&self) -> &str

Returns the decimal digits without the leading #.

Examples found in repository?
examples/recovery_property.rs (line 64)
18fn main() {
19    let base = "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION((''),'2;1');\n\
20                FILE_NAME('n','t',(''),(''),'p','o','a');\nFILE_SCHEMA(('IFC4'));\nENDSEC;\nDATA;\n\
21                #1= IFCPERSON($,$,'a;b',$,$,$,$,$);\n\
22                #2= IFCPIXELTEXTURE(1,1,8,(\"00AA;BB\"));\n\
23                #3= IFCORGANIZATION($,'o''x',$,$,$); /* c;c */\n\
24                #4= IFCDOOR('real');\nENDSEC;\nEND-ISO-10303-21;\n";
25
26    let mut state = 0x5eed_1234_u64;
27    let mut recovered = 0usize;
28    let mut fabricated = 0usize;
29    let mut span_faults = 0usize;
30
31    for _ in 0..20_000 {
32        let mut bytes = base.as_bytes().to_vec();
33        // Corrupt 1-3 bytes anywhere in the DATA region.
34        let edits = 1 + (lcg(&mut state) % 3) as usize;
35        for _ in 0..edits {
36            let at = 150 + (lcg(&mut state) as usize % (bytes.len() - 150));
37            match lcg(&mut state) % 3 {
38                0 => bytes[at] = b'@',
39                1 => {
40                    bytes.remove(at);
41                }
42                _ => bytes[at] = (lcg(&mut state) % 128) as u8,
43            }
44        }
45
46        let Ok(outcome) = parse_with(
47            &bytes,
48            ParseOptions::default().on_malformed_record(OnMalformed::Skip),
49        ) else {
50            continue;
51        };
52        recovered += 1;
53
54        for diagnostic in &outcome.diagnostics {
55            let span = diagnostic.span();
56            if span.start > span.end || span.end > bytes.len() {
57                span_faults += 1;
58            }
59        }
60
61        // Every kept record must appear verbatim in the surviving source: its
62        // `#id=` must exist outside any diagnostic-covered range.
63        for record in &outcome.exchange.data.records {
64            let needle = format!("#{}=", record.id.as_str());
65            let found = String::from_utf8_lossy(&bytes).contains(&needle)
66                || String::from_utf8_lossy(&bytes).contains(&format!("#{} =", record.id.as_str()));
67            if !found {
68                fabricated += 1;
69                eprintln!(
70                    "FABRICATED {} in:\n{}",
71                    needle,
72                    String::from_utf8_lossy(&bytes)
73                );
74            }
75        }
76    }
77
78    println!("recovered={recovered} fabricated={fabricated} span_faults={span_faults}");
79    assert_eq!(fabricated, 0, "recovery invented records");
80    assert_eq!(span_faults, 0, "diagnostic span out of bounds");
81    println!("PROPERTY PROBE OK");
82}

Trait Implementations§

Source§

impl Clone for InstanceId

Source§

fn clone(&self) -> InstanceId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InstanceId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for InstanceId

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for InstanceId

Source§

impl From<u64> for InstanceId

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl Hash for InstanceId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for InstanceId

Source§

fn cmp(&self, other: &InstanceId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for InstanceId

Source§

fn eq(&self, other: &InstanceId) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for InstanceId

Source§

fn partial_cmp(&self, other: &InstanceId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for InstanceId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.