Skip to content

Commit f807b24

Browse files
committed
Adds suggested changes
1 parent d3bbbd5 commit f807b24

File tree

9 files changed

+149
-142
lines changed

9 files changed

+149
-142
lines changed

ion-schema/src/model/bag.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl<T> Bag<T> {
5858
pub fn iter(&self) -> impl Iterator<Item = &T> {
5959
self.items.iter()
6060
}
61+
62+
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
63+
self.items.iter_mut()
64+
}
6165
}
6266

6367
impl<T> IntoIterator for Bag<T> {

ion-schema/src/model/constraints/annotations/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl ConstraintName for Annotations {
3232
pub struct Annotations {
3333
variant: AnnotationsVariant,
3434
}
35-
impl_type_ref_walker!(Annotations, as_annotations_v2_standard());
35+
impl_type_ref_walker!(Annotations, as_annotations_v2_standard_mut());
3636

3737
impl Annotations {
3838
pub fn as_annotations_v1(&self) -> Option<&AnnotationsV1> {
@@ -56,6 +56,14 @@ impl Annotations {
5656
None
5757
}
5858
}
59+
60+
pub fn as_annotations_v2_standard_mut(&mut self) -> Option<&mut AnnotationsV2Standard> {
61+
if let AnnotationsVariant::V2Standard(ref mut variant) = &mut self.variant {
62+
Some(variant)
63+
} else {
64+
None
65+
}
66+
}
5967
}
6068

6169
#[derive(Debug, PartialEq, Clone)]

ion-schema/src/model/constraints/any_constraint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! any_constraint {
3939
)+
4040

4141
impl TypeRefWalker for AnyConstraint {
42-
fn walk<V: TypeRefVisitor>(&self, visitor: &mut V) {
42+
fn walk<V: TypeRefVisitor>(&mut self, visitor: &mut V) {
4343
match self {
4444
$(AnyConstraint::$name(constraint) => constraint.walk(visitor),
4545
)+

ion-schema/src/model/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl From<Element> for SchemaItem {
3333
}
3434

3535
impl TypeRefWalker for SchemaItem {
36-
fn walk<V: TypeRefVisitor>(&self, visitor: &mut V) {
36+
fn walk<V: TypeRefVisitor>(&mut self, visitor: &mut V) {
3737
if let SchemaItem::Type(_, t) = self {
3838
t.walk(visitor)
3939
}

ion-schema/src/model/type_argument.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ enum TypeArgumentKind {
5252
}
5353

5454
impl TypeRefWalker for TypeArgument {
55-
fn walk<V: TypeRefVisitor>(&self, visitor: &mut V) {
56-
match &self.kind {
57-
TypeArgumentKind::TypeReference(ref type_ref) => visitor.visit(type_ref),
58-
TypeArgumentKind::InlineType(type_def) => type_def.walk(visitor),
55+
fn walk<V: TypeRefVisitor>(&mut self, visitor: &mut V) {
56+
match &mut self.kind {
57+
TypeArgumentKind::TypeReference(ref mut type_ref) => visitor.visit(type_ref),
58+
TypeArgumentKind::InlineType(ref mut type_def) => type_def.walk(visitor),
5959
}
6060
}
6161
}

ion-schema/src/model/type_reference.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ pub struct TypeReference {
1818
}
1919

2020
impl TypeReference {
21-
fn new<S: Into<String>>(type_name: S) -> Self {
21+
/// Creates a `TypeReference` for a type name that is defined in or imported to the current
22+
/// [`SchemaDocument`].
23+
fn local<S: Into<String>>(type_name: S) -> Self {
2224
TypeReference {
2325
schema_id: None,
2426
type_name: type_name.into(),
2527
resolved_type_coordinates: None,
2628
}
2729
}
2830

31+
/// Creates a `TypeReference` that is an inline import from another schema.
2932
pub fn imported<A: Into<String>, B: Into<String>>(schema_id: A, type_name: B) -> Self {
3033
TypeReference {
3134
schema_id: Some(schema_id.into()),
@@ -46,14 +49,15 @@ impl TypeReference {
4649
self.resolved_type_coordinates
4750
}
4851

49-
pub(crate) fn resolve_type_coordinates(&mut self, type_coordinates: Option<TypeCoordinates>) {
52+
/// Sets the [`TypeCoordinates`] of this `TypeReference`.
53+
pub(crate) fn set_type_coordinates(&mut self, type_coordinates: Option<TypeCoordinates>) {
5054
self.resolved_type_coordinates = type_coordinates
5155
}
5256
}
5357

5458
impl<T: Into<String>> From<T> for TypeReference {
5559
fn from(value: T) -> Self {
56-
TypeReference::new(value)
60+
TypeReference::local(value)
5761
}
5862
}
5963

@@ -110,7 +114,7 @@ mod tests {
110114
#[test]
111115
fn from_string() {
112116
let from_value = "foo";
113-
let expected = TypeReference::new("foo");
117+
let expected = TypeReference::local("foo");
114118
assert_eq!(expected, from_value.into())
115119
}
116120

@@ -126,7 +130,7 @@ mod tests {
126130
}
127131

128132
#[rstest]
129-
#[case::type_name("foo", TypeReference::new("foo"))]
133+
#[case::type_name("foo", TypeReference::local("foo"))]
130134
#[case::inline_import("{id:\"foo.isl\",type:bar}", TypeReference::imported("foo.isl", "bar"))]
131135
fn type_reference_try_read_ok(#[case] ion: &str, #[case] expected: TypeReference) {
132136
let expected = Ok(expected);

0 commit comments

Comments
 (0)