Skip to content

Commit 5d18c08

Browse files
committed
add docstring
1 parent 3c1df18 commit 5d18c08

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/ast/value.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,42 @@ use crate::{ast::Ident, tokenizer::Span};
3030
#[cfg(feature = "visitor")]
3131
use sqlparser_derive::{Visit, VisitMut};
3232

33-
/// Primitive SQL values such as number and string
33+
34+
35+
/// Wraps a primitive SQL [`Value`] with its [`Span`] location
36+
///
37+
/// # Example: create a `ValueWithSpan` from a `Value`
38+
/// ```
39+
/// # use sqlparser::ast::{Value, ValueWithSpan};
40+
/// # use sqlparser::tokenizer::{Location, Span};
41+
/// let value = Value::SingleQuotedString(String::from("endpoint"));
42+
/// // from line 1, column 1 to line 1, column 7
43+
/// let span = Span::new(Location::new(1, 1), Location::new(1, 7));
44+
/// let value_with_span = value.with_span(span);
45+
/// ```
46+
///
47+
/// # Example: create a `ValueWithSpan` from a `Value` with an empty span
48+
///
49+
/// You can call [`Value::with_empty_span`] to create a `ValueWithSpan` with an empty span
50+
/// ```
51+
/// # use sqlparser::ast::{Value, ValueWithSpan};
52+
/// # use sqlparser::tokenizer::{Location, Span};
53+
/// let value = Value::SingleQuotedString(String::from("endpoint"));
54+
/// let value_with_span = value.with_empty_span();
55+
/// assert_eq!(value_with_span.span, Span::empty());
56+
/// ```
57+
///
58+
/// You can also use the [`From`] trait to convert `ValueWithSpan` to/from `Value`s
59+
/// ```
60+
/// # use sqlparser::ast::{Value, ValueWithSpan};
61+
/// # use sqlparser::tokenizer::{Location, Span};
62+
/// let value = Value::SingleQuotedString(String::from("endpoint"));
63+
/// // converting `Value` to `ValueWithSpan` results in an empty span
64+
/// let value_with_span: ValueWithSpan = value.into();
65+
/// assert_eq!(value_with_span.span, Span::empty());
66+
/// // convert back to `Value`
67+
/// let value: Value = value_with_span.into();
68+
/// ```
3469
#[derive(Debug, Clone, Eq)]
3570
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3671
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]

0 commit comments

Comments
 (0)