mirror of https://github.com/kdl-org/kdl-rs.git
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:
parent
3d8778a610
commit
04471a537e
|
|
@ -60,14 +60,8 @@ impl KdlDocument {
|
||||||
/// but may become invalidated if the document is mutated. We do not currently
|
/// but may become invalidated if the document is mutated. We do not currently
|
||||||
/// guarantee this to yield any particularly consistent results at that point.
|
/// guarantee this to yield any particularly consistent results at that point.
|
||||||
#[cfg(feature = "span")]
|
#[cfg(feature = "span")]
|
||||||
pub fn span(&self) -> &SourceSpan {
|
pub fn span(&self) -> SourceSpan {
|
||||||
&self.span
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this document's span.
|
/// Sets this document's span.
|
||||||
|
|
@ -587,8 +581,8 @@ foo 1 bar=0xdeadbeef {
|
||||||
|
|
||||||
#[cfg(feature = "span")]
|
#[cfg(feature = "span")]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check_span(expected: &str, span: &SourceSpan, source: &impl miette::SourceCode) {
|
fn check_span(expected: &str, span: SourceSpan, source: &impl miette::SourceCode) {
|
||||||
let span = source.read_span(span, 0, 0).unwrap();
|
let span = source.read_span(&span, 0, 0).unwrap();
|
||||||
let span = std::str::from_utf8(span.data()).unwrap();
|
let span = std::str::from_utf8(span.data()).unwrap();
|
||||||
assert_eq!(span, expected);
|
assert_eq!(span, expected);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/entry.rs
10
src/entry.rs
|
|
@ -73,14 +73,8 @@ impl KdlEntry {
|
||||||
/// but may become invalidated if the document is mutated. We do not currently
|
/// but may become invalidated if the document is mutated. We do not currently
|
||||||
/// guarantee this to yield any particularly consistent results at that point.
|
/// guarantee this to yield any particularly consistent results at that point.
|
||||||
#[cfg(feature = "span")]
|
#[cfg(feature = "span")]
|
||||||
pub fn span(&self) -> &SourceSpan {
|
pub fn span(&self) -> SourceSpan {
|
||||||
&self.span
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this entry's span.
|
/// Sets this entry's span.
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,8 @@ impl KdlIdentifier {
|
||||||
/// but may become invalidated if the document is mutated. We do not currently
|
/// but may become invalidated if the document is mutated. We do not currently
|
||||||
/// guarantee this to yield any particularly consistent results at that point.
|
/// guarantee this to yield any particularly consistent results at that point.
|
||||||
#[cfg(feature = "span")]
|
#[cfg(feature = "span")]
|
||||||
pub fn span(&self) -> &SourceSpan {
|
pub fn span(&self) -> SourceSpan {
|
||||||
&self.span
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this identifier's span.
|
/// Sets this identifier's span.
|
||||||
|
|
|
||||||
10
src/node.rs
10
src/node.rs
|
|
@ -76,14 +76,8 @@ impl KdlNode {
|
||||||
/// but may become invalidated if the document is mutated. We do not currently
|
/// but may become invalidated if the document is mutated. We do not currently
|
||||||
/// guarantee this to yield any particularly consistent results at that point.
|
/// guarantee this to yield any particularly consistent results at that point.
|
||||||
#[cfg(feature = "span")]
|
#[cfg(feature = "span")]
|
||||||
pub fn span(&self) -> &SourceSpan {
|
pub fn span(&self) -> SourceSpan {
|
||||||
&self.span
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this node's span.
|
/// Sets this node's span.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue