1 // Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU Proc Macro Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 // <http://www.gnu.org/licenses/>.
29 pub struct Ident(pub(crate) bridge::ident::Ident);
32 /// Creates a new identifier.
36 /// * `string` - A valid identifier.
37 /// * `span` - The span of the identifier.
41 /// The `string` argument must be a valid identifier permitted by the
42 /// language, otherwise the function will panic.
43 pub fn new(string: &str, span: Span) -> Self {
44 Ident(bridge::ident::Ident::new(string, span.0))
47 /// Creates a new raw identifier.
51 /// * `string` - A valid identifier.
52 /// * `span` - The span of the identifier.
56 /// The `string` argument must be a valid identifier permitted by the
57 /// language. Furthermore, it should not be a keyword used in path
58 /// segments, otherwise this function will panic.
59 pub fn new_raw(string: &str, span: Span) -> Self {
60 Ident(bridge::ident::Ident::new_raw(string, span.0))
63 /// Return the span of the identifier
64 pub fn span(&self) -> Span {
68 /// Change the span of the identifier.
72 /// * `span` - The new span value.
73 pub fn set_span(&mut self, span: Span) {
74 self.0.set_span(span.0);
78 impl fmt::Display for Ident {
79 /// Display as lossless converted string.
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85 impl fmt::Debug for Ident {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {