mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-30 08:20:48 +08:00
git-ref-format: rename namespace functions
The namespace functions can read confusingly: * `namespaced` - the naming sounds like it is namespacing the input, when in fact it is ensuring that the input is namespaced. * `add_namespace` - can be read as adding the namespace to the end of a ref, when in fact it is placed at the beginning. Change the naming, respectively, to: * `to_namespaced` - this uses the conversion naming convention detailed here[0]. * `with_namespace` - reads as plainly namespacing the ref string. [0]: https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -103,7 +103,7 @@ impl<'de: 'a, 'a> Decode<'de> for Namespaced<'a> {
|
||||
#[inline]
|
||||
fn decode(d: &mut Decoder<'de>) -> Result<Self, decode::Error> {
|
||||
Decode::decode(d).and_then(|s: &RefStr| {
|
||||
s.namespaced()
|
||||
s.to_namespaced()
|
||||
.ok_or(decode::Error::Message("not a namespaced ref"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ impl<'a> Qualified<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn namespaced(&self) -> Option<Namespaced> {
|
||||
pub fn to_namespaced(&self) -> Option<Namespaced> {
|
||||
self.0.as_ref().into()
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl<'a> Qualified<'a> {
|
||||
///
|
||||
/// Creates a new [`Namespaced`] by prefxing `self` with
|
||||
/// "refs/namespaces/<ns>".
|
||||
pub fn add_namespace<'b>(&self, ns: Component<'b>) -> Namespaced<'a> {
|
||||
pub fn with_namespace<'b>(&self, ns: Component<'b>) -> Namespaced<'a> {
|
||||
Namespaced(Cow::Owned(
|
||||
IntoIterator::into_iter([lit::Refs.into(), lit::Namespaces.into(), ns])
|
||||
.chain(self.0.components())
|
||||
@@ -352,7 +352,7 @@ impl<'a> Namespaced<'a> {
|
||||
|
||||
pub fn strip_namespace_recursive<'b>(&self) -> Qualified<'b> {
|
||||
let mut strip = self.strip_namespace();
|
||||
while let Some(ns) = strip.namespaced() {
|
||||
while let Some(ns) = strip.to_namespaced() {
|
||||
strip = ns.strip_namespace();
|
||||
}
|
||||
strip
|
||||
|
||||
@@ -193,7 +193,7 @@ impl RefStr {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn namespaced(&self) -> Option<Namespaced> {
|
||||
pub fn to_namespaced(&self) -> Option<Namespaced> {
|
||||
self.into()
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for Namespaced<'a> {
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Deserialize::deserialize(deserializer).and_then(|s: &RefStr| {
|
||||
s.namespaced()
|
||||
s.to_namespaced()
|
||||
.ok_or_else(|| de::Error::custom("not a namespaced ref"))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user