/src/gitoxide/gix-attributes/src/assignment.rs
Line | Count | Source |
1 | | use std::fmt::Write; |
2 | | |
3 | | use bstr::ByteSlice; |
4 | | |
5 | | use crate::{Assignment, AssignmentRef, NameRef, StateRef}; |
6 | | |
7 | | impl<'a> AssignmentRef<'a> { |
8 | 8.45M | pub(crate) fn new(name: NameRef<'a>, state: StateRef<'a>) -> AssignmentRef<'a> { |
9 | 8.45M | AssignmentRef { name, state } |
10 | 8.45M | } Unexecuted instantiation: <gix_attributes::AssignmentRef>::new <gix_attributes::AssignmentRef>::new Line | Count | Source | 8 | 26.7k | pub(crate) fn new(name: NameRef<'a>, state: StateRef<'a>) -> AssignmentRef<'a> { | 9 | 26.7k | AssignmentRef { name, state } | 10 | 26.7k | } |
<gix_attributes::AssignmentRef>::new Line | Count | Source | 8 | 8.42M | pub(crate) fn new(name: NameRef<'a>, state: StateRef<'a>) -> AssignmentRef<'a> { | 9 | 8.42M | AssignmentRef { name, state } | 10 | 8.42M | } |
|
11 | | |
12 | | /// Turn this reference into its owned counterpart. |
13 | 4.76M | pub fn to_owned(self) -> Assignment { |
14 | 4.76M | self.into() |
15 | 4.76M | } Unexecuted instantiation: <gix_attributes::AssignmentRef>::to_owned <gix_attributes::AssignmentRef>::to_owned Line | Count | Source | 13 | 26.7k | pub fn to_owned(self) -> Assignment { | 14 | 26.7k | self.into() | 15 | 26.7k | } |
<gix_attributes::AssignmentRef>::to_owned Line | Count | Source | 13 | 4.73M | pub fn to_owned(self) -> Assignment { | 14 | 4.73M | self.into() | 15 | 4.73M | } |
|
16 | | } |
17 | | |
18 | | impl<'a> From<AssignmentRef<'a>> for Assignment { |
19 | 4.76M | fn from(a: AssignmentRef<'a>) -> Self { |
20 | 4.76M | Assignment { |
21 | 4.76M | name: a.name.to_owned(), |
22 | 4.76M | state: a.state.to_owned(), |
23 | 4.76M | } |
24 | 4.76M | } Unexecuted instantiation: <gix_attributes::Assignment as core::convert::From<gix_attributes::AssignmentRef>>::from <gix_attributes::Assignment as core::convert::From<gix_attributes::AssignmentRef>>::from Line | Count | Source | 19 | 26.7k | fn from(a: AssignmentRef<'a>) -> Self { | 20 | 26.7k | Assignment { | 21 | 26.7k | name: a.name.to_owned(), | 22 | 26.7k | state: a.state.to_owned(), | 23 | 26.7k | } | 24 | 26.7k | } |
<gix_attributes::Assignment as core::convert::From<gix_attributes::AssignmentRef>>::from Line | Count | Source | 19 | 4.73M | fn from(a: AssignmentRef<'a>) -> Self { | 20 | 4.73M | Assignment { | 21 | 4.73M | name: a.name.to_owned(), | 22 | 4.73M | state: a.state.to_owned(), | 23 | 4.73M | } | 24 | 4.73M | } |
|
25 | | } |
26 | | |
27 | | impl<'a> Assignment { |
28 | | /// Provide a ref type to this owned instance. |
29 | 3.68M | pub fn as_ref(&'a self) -> AssignmentRef<'a> { |
30 | 3.68M | AssignmentRef::new(self.name.as_ref(), self.state.as_ref()) |
31 | 3.68M | } Unexecuted instantiation: <gix_attributes::Assignment>::as_ref Unexecuted instantiation: <gix_attributes::Assignment>::as_ref <gix_attributes::Assignment>::as_ref Line | Count | Source | 29 | 3.68M | pub fn as_ref(&'a self) -> AssignmentRef<'a> { | 30 | 3.68M | AssignmentRef::new(self.name.as_ref(), self.state.as_ref()) | 31 | 3.68M | } |
|
32 | | } |
33 | | |
34 | | impl std::fmt::Display for AssignmentRef<'_> { |
35 | 3.68M | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
36 | 3.68M | match self.state { |
37 | 3.57M | StateRef::Set => f.write_str(self.name.as_str()), |
38 | | StateRef::Unset => { |
39 | 13.8k | f.write_char('-')?; |
40 | 13.8k | f.write_str(self.name.as_str()) |
41 | | } |
42 | 95.5k | StateRef::Value(v) => { |
43 | 95.5k | f.write_str(self.name.as_str())?; |
44 | 95.5k | f.write_char('=')?; |
45 | 95.5k | f.write_str(v.as_bstr().to_str_lossy().as_ref()) |
46 | | } |
47 | | StateRef::Unspecified => { |
48 | 3.37k | f.write_char('!')?; |
49 | 3.37k | f.write_str(self.name.as_str()) |
50 | | } |
51 | | } |
52 | 3.68M | } Unexecuted instantiation: <gix_attributes::AssignmentRef as core::fmt::Display>::fmt Unexecuted instantiation: <gix_attributes::AssignmentRef as core::fmt::Display>::fmt <gix_attributes::AssignmentRef as core::fmt::Display>::fmt Line | Count | Source | 35 | 3.68M | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 36 | 3.68M | match self.state { | 37 | 3.57M | StateRef::Set => f.write_str(self.name.as_str()), | 38 | | StateRef::Unset => { | 39 | 13.8k | f.write_char('-')?; | 40 | 13.8k | f.write_str(self.name.as_str()) | 41 | | } | 42 | 95.5k | StateRef::Value(v) => { | 43 | 95.5k | f.write_str(self.name.as_str())?; | 44 | 95.5k | f.write_char('=')?; | 45 | 95.5k | f.write_str(v.as_bstr().to_str_lossy().as_ref()) | 46 | | } | 47 | | StateRef::Unspecified => { | 48 | 3.37k | f.write_char('!')?; | 49 | 3.37k | f.write_str(self.name.as_str()) | 50 | | } | 51 | | } | 52 | 3.68M | } |
|
53 | | } |