feat(spans): rework the span API to be strictly by-val (#60)

BREAKING CHANGE: this removes all the `.span_mut()` methods and changes the signature for `.span()`.
This commit is contained in:
Aria Beingessner 2022-12-04 13:19:58 -05:00 committed by GitHub
parent 3d8778a610
commit 04471a537e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 34 deletions

View File

@ -60,14 +60,8 @@ impl KdlDocument {
/// but may become invalidated if the document is mutated. We do not currently
/// guarantee this to yield any particularly consistent results at that point.
#[cfg(feature = "span")]
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// Gets a mutable reference to this document's span.
#[cfg(feature = "span")]
pub fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
pub fn span(&self) -> SourceSpan {
self.span
}
/// Sets this document's span.
@ -587,8 +581,8 @@ foo 1 bar=0xdeadbeef {
#[cfg(feature = "span")]
#[track_caller]
fn check_span(expected: &str, span: &SourceSpan, source: &impl miette::SourceCode) {
let span = source.read_span(span, 0, 0).unwrap();
fn check_span(expected: &str, span: SourceSpan, source: &impl miette::SourceCode) {
let span = source.read_span(&span, 0, 0).unwrap();
let span = std::str::from_utf8(span.data()).unwrap();
assert_eq!(span, expected);
}

View File

@ -73,14 +73,8 @@ impl KdlEntry {
/// but may become invalidated if the document is mutated. We do not currently
/// guarantee this to yield any particularly consistent results at that point.
#[cfg(feature = "span")]
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// Gets a mutable reference to this entry's span.
#[cfg(feature = "span")]
pub fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
pub fn span(&self) -> SourceSpan {
self.span
}
/// Sets this entry's span.

View File

@ -46,14 +46,8 @@ impl KdlIdentifier {
/// but may become invalidated if the document is mutated. We do not currently
/// guarantee this to yield any particularly consistent results at that point.
#[cfg(feature = "span")]
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// Gets a mutable reference to this identifier's span.
#[cfg(feature = "span")]
pub fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
pub fn span(&self) -> SourceSpan {
self.span
}
/// Sets this identifier's span.

View File

@ -76,14 +76,8 @@ impl KdlNode {
/// but may become invalidated if the document is mutated. We do not currently
/// guarantee this to yield any particularly consistent results at that point.
#[cfg(feature = "span")]
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// Gets a mutable reference to this node's span.
#[cfg(feature = "span")]
pub fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
pub fn span(&self) -> SourceSpan {
self.span
}
/// Sets this node's span.