Skip to content

Commit

Permalink
Add internal::InnerAndOuterAnnotations::inner/outer_annotations/_mut()
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger committed Nov 3, 2019
1 parent d3967c6 commit a47566b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/gen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ impl Function {
}

impl internal::InnerAndOuterAnnotations for Function {
fn inner_annotations(&mut self) -> &mut Vec<String> {
fn inner_annotations_mut(&mut self) -> &mut Vec<String> {
self.body.annotations_mut()
}

fn outer_annotations(&mut self) -> &mut Vec<String> {
fn inner_annotations(&self) -> &[String] {
self.body.annotations()
}
fn outer_annotations_mut(&mut self) -> &mut Vec<String> {
self.signature.annotations_mut()
}
fn outer_annotations(&self) -> &[String] {
self.signature.annotations()
}
}

impl internal::Generics for Function {
Expand Down
10 changes: 8 additions & 2 deletions src/gen/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ impl Module {
}

impl internal::InnerAndOuterAnnotations for Module {
fn inner_annotations(&mut self) -> &mut Vec<String> {
fn inner_annotations_mut(&mut self) -> &mut Vec<String> {
&mut self.inner_annotations
}
fn inner_annotations(&self) -> &[String] {
self.inner_annotations.as_slice()
}

fn outer_annotations(&mut self) -> &mut Vec<String> {
fn outer_annotations_mut(&mut self) -> &mut Vec<String> {
&mut self.outer_annotations
}
fn outer_annotations(&self) -> &[String] {
self.outer_annotations.as_slice()
}
}

impl internal::Docs for Module {
Expand Down
6 changes: 4 additions & 2 deletions src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ pub trait Annotations {
/// Internal trait to get access to the container storing the inner and outer annotations.
/// Used for the generic implementation of `InnerAndOuterAnnotationExt`
pub trait InnerAndOuterAnnotations {
fn inner_annotations(&mut self) -> &mut Vec<String>;
fn outer_annotations(&mut self) -> &mut Vec<String>;
fn inner_annotations_mut(&mut self) -> &mut Vec<String>;
fn inner_annotations(&self) -> &[String];
fn outer_annotations_mut(&mut self) -> &mut Vec<String>;
fn outer_annotations(&self) -> &[String];
}

/// Internal trait to get access to the container storing the fields.
Expand Down
8 changes: 4 additions & 4 deletions src/traits/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait InnerAndOuterAnnotationExt {
impl<T: InnerAndOuterAnnotations> InnerAndOuterAnnotationExt for T {
/// Add a single inner annotation.
fn add_inner_annotation(&mut self, annotation: impl ToString) -> &mut Self {
self.inner_annotations().push(annotation.to_string());
self.inner_annotations_mut().push(annotation.to_string());
self
}

Expand All @@ -67,14 +67,14 @@ impl<T: InnerAndOuterAnnotations> InnerAndOuterAnnotationExt for T {
&mut self,
annotations: impl IntoIterator<Item = impl ToString>,
) -> &mut Self {
self.inner_annotations()
self.inner_annotations_mut()
.extend(annotations.into_iter().map(|a| a.to_string()));
self
}

/// Add a single outer annotation.
fn add_outer_annotation(&mut self, annotation: impl ToString) -> &mut Self {
self.outer_annotations().push(annotation.to_string());
self.outer_annotations_mut().push(annotation.to_string());
self
}

Expand All @@ -83,7 +83,7 @@ impl<T: InnerAndOuterAnnotations> InnerAndOuterAnnotationExt for T {
&mut self,
annotations: impl IntoIterator<Item = impl ToString>,
) -> &mut Self {
self.outer_annotations()
self.outer_annotations_mut()
.extend(annotations.into_iter().map(|a| a.to_string()));
self
}
Expand Down

0 comments on commit a47566b

Please sign in to comment.