feat: Like `Option`, add `take` API to allow ownership transfer

This will be useful when mutably walking an expression tree and reusing
existing allocations.
pull/24376/head
Stuart Carnie 2023-04-18 16:46:04 +10:00
parent 7cb3048035
commit 5987bc1ea2
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
1 changed files with 6 additions and 1 deletions

View File

@ -23,8 +23,8 @@ use nom::character::complete::{alpha1, alphanumeric1};
use nom::combinator::{map, not, recognize};
use nom::multi::many0_count;
use nom::sequence::{pair, preceded};
use std::fmt;
use std::fmt::{Display, Formatter, Write};
use std::{fmt, mem};
/// Parse an unquoted InfluxQL identifier.
pub(crate) fn unquoted_identifier(i: &str) -> ParseResult<&str, &str> {
@ -54,6 +54,11 @@ impl Identifier {
pub fn requires_quotes(&self) -> bool {
nom::sequence::terminated(unquoted_identifier, nom::combinator::eof)(&self.0).is_err()
}
/// Takes the string value out of the identifier, leaving a default string value in its place.
pub fn take(&mut self) -> String {
mem::take(&mut self.0)
}
}
impl Display for Identifier {