[][src]Struct oceanpkg::drop::name::Query

pub struct Query<Name = String, Version = Name> {
    pub scope: Option<Name>,
    pub name: Name,
    pub version: Option<Version>,
}

A drop lookup in the form (<scope>/)?<name>(@<version>)?.

By default, String is used for the generic Name and Version types.

When performing zero-copy parsing, it is recommended to use Query<&str>.

Fields

scope: Option<Name>

The drop's owner.

name: Name

The drop's name.

version: Option<Version>

The drop's version requirement.

Methods

impl<N, V> Query<N, V>[src]

pub fn new<A, B, C>(scope: A, name: B, version: C) -> Self where
    A: Into<N>,
    B: Into<N>,
    C: Into<V>, 
[src]

Creates a new Query instance with scope, name, and version.

Examples

This serves as a convenience to not need to deal with explicitly wrapping types with Some.

use oceanpkg::drop::name::Query;

let query = Query::<&str>::new("core", "wget", "1.20");

assert_eq!(query.to_string(), "core/wget@1.20");

pub fn parse<Q, NE, VE>(query: Q) -> Result<Self, ParseError<NE, VE>> where
    Q: TryInto<Self, Error = ParseError<NE, VE>>, 
[src]

Attempts to create a new instance by strictly parsing name.

pub fn parse_liberal<'a>(query: &'a str) -> Self where
    &'a str: Into<N>,
    &'a str: Into<V>, 
[src]

Creates a new instance by parsing query in a non-strict manner.

Examples

use oceanpkg::drop::name::Query;

let scope   = "core";
let name    = "ruby";
let version = "2.6";

let query_string = format!("{}/{}@{}", scope, name, version);
let query = Query::<&str>::parse_liberal(&query_string);

assert_eq!(query.scope,   Some(scope));
assert_eq!(query.name,    name);
assert_eq!(query.version, Some(version));

assert_eq!(query.to_string(), query_string);

pub fn cast<A, B>(self) -> Query<A, B> where
    N: Into<A>,
    V: Into<B>, 
[src]

Converts self into a new Query by performing an Into conversion over all fields.

pub fn try_cast<A, B>(
    self
) -> Result<Query<A, B>, ParseError<N::Error, V::Error>> where
    N: TryInto<A>,
    V: TryInto<B>, 
[src]

Converts self into a new Query by performing an Into conversion over all fields.

pub fn as_ref(&self) -> Query<&N, &V>[src]

Takes a shared reference to the fields of this query.

See Query::as_mut for the mutable equivalent.

pub fn to_ref<A>(&self) -> Query<&A> where
    N: AsRef<A>,
    V: AsRef<A>,
    A: ?Sized
[src]

Takes a shared reference to the fields of this query as type A.

See Query::to_mut for the mutable equivalent.

Examples

use oceanpkg::drop::name::Query;

let query: Query<String> = //
let by_ref: Query<&str> = query.to_ref();

assert_eq!(query, by_ref);

pub fn as_mut(&mut self) -> Query<&mut N, &mut V>[src]

Takes a mutable reference to the fields of this query.

See Query::as_ref for the immutable equivalent.

pub fn to_mut<A>(&mut self) -> Query<&mut A> where
    N: AsMut<A>,
    V: AsMut<A>,
    A: ?Sized
[src]

Takes a mutable reference to the fields of this query as type A.

See Query::to_ref for the immutable equivalent.

pub fn scoped_name(&self) -> Option<ScopedName<&N>>[src]

Returns the scoped name for self if scope exists.

pub fn cmp_version<A, B>(&self, other: &Query<A, B>) -> Option<Ordering> where
    V: PartialOrd<B>, 
[src]

Performs a partial version comparison between self and other.

Returns None if:

  • One version is Some and the other is Some.
  • <V as PartialOrd<B>>::partial_cmp returns None.

pub fn file_name(&self) -> String where
    N: Display,
    V: Display
[src]

Returns the name of self formatted for the filesystem.

pub fn tarball_name(&self) -> String where
    N: Display,
    V: Display
[src]

Returns the name of self packaged as a tarball.

pub fn join_to_url(&self, url: &Url) -> Result<Url, ParseError> where
    N: Display,
    V: AsRef<str>, 
[src]

Returns a new Url with the fields of self appended.

Examples

If scope is empty, it is replaced with core.

use oceanpkg::drop::name::Query;
use url::Url;

let query = "wget@1.20";
let query = Query::<&str>::parse_liberal(query);

let url = Url::parse("https://www.oceanpkg.org").unwrap();
let url = query.join_to_url(&url).unwrap();

assert_eq!(url.as_str(), "https://www.oceanpkg.org/u/core/p/wget?version=1.20");

impl<'n, 'v, N: ?Sized, V: ?Sized> Query<&'n N, &'v V>[src]

pub fn to_owned(&self) -> Query<N::Owned, V::Owned> where
    N: ToOwned,
    V: ToOwned
[src]

Returns the result of calling ToOwned::to_owned on the fields of self.

Examples

use oceanpkg::drop::name::Query;

let query: Query<&str> = Query::new("core", "wget", "*");
let owned: Query<String> = query.to_owned();

assert_eq!(query, owned);

Trait Implementations

impl<Name: Clone, Version: Clone> Clone for Query<Name, Version>[src]

impl<Name: Copy, Version: Copy> Copy for Query<Name, Version>[src]

impl<Name: Debug, Version: Debug> Debug for Query<Name, Version>[src]

impl<'de, N, V, NE, VE> Deserialize<'de> for Query<N, V> where
    &'a str: TryInto<Query<N, V>, Error = ParseError<NE, VE>>,
    ParseError<NE, VE>: Display
[src]

impl<N: Display, V: Display> Display for Query<N, V>[src]

impl<Name: Eq, Version: Eq> Eq for Query<Name, Version>[src]

impl<N, V> From<ScopedName<N>> for Query<N, V>[src]

impl<Name: Hash, Version: Hash> Hash for Query<Name, Version>[src]

impl<Name: Ord, Version: Ord> Ord for Query<Name, Version>[src]

impl<A, B, X, Y> PartialEq<Query<X, Y>> for Query<A, B> where
    A: PartialEq<X>,
    B: PartialEq<Y>, 
[src]

impl<Name: PartialOrd, Version: PartialOrd> PartialOrd<Query<Name, Version>> for Query<Name, Version>[src]

impl<N, V> Serialize for Query<N, V> where
    Query<N, V>: Display
[src]

impl<Name, Version> StructuralEq for Query<Name, Version>[src]

impl<'a, N, V> TryFrom<&'a str> for Query<N, V> where
    &'a str: TryInto<N>,
    &'a str: TryInto<V>, 
[src]

type Error = ParseError<<&'a str as TryInto<N>>::Error, <&'a str as TryInto<V>>::Error>

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<Name, Version> RefUnwindSafe for Query<Name, Version> where
    Name: RefUnwindSafe,
    Version: RefUnwindSafe

impl<Name, Version> Send for Query<Name, Version> where
    Name: Send,
    Version: Send

impl<Name, Version> Sync for Query<Name, Version> where
    Name: Sync,
    Version: Sync

impl<Name, Version> Unpin for Query<Name, Version> where
    Name: Unpin,
    Version: Unpin

impl<Name, Version> UnwindSafe for Query<Name, Version> where
    Name: UnwindSafe,
    Version: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.