Struct GitCredential

Source
pub struct GitCredential {
    pub url: Option<Url>,
    pub protocol: Option<String>,
    pub host: Option<String>,
    pub path: Option<String>,
    pub username: Option<String>,
    pub password: Option<String>,
}
Expand description

Holds the values of all parameters supported by git-credential

Fields§

§url: Option<Url>

The url field is treated specially by git-credential. Setting the url corresponds to setting all the other fields as part of the url.

The url has the following format: <protocol>://<username>:<password>@<host>/<path>.

§protocol: Option<String>

The protocol over which the credential will be used (e.g., https).

§host: Option<String>

The remote hostname for a network credential (e.g., example.com).

§path: Option<String>

The path with which the credential will be used. E.g., for accessing a remote https repository, this will be the repository’s path on the server.

§username: Option<String>

The credential’s username, if we already have one (e.g., from a URL, from the user, or from a previously run helper).

§password: Option<String>

The credential’s password, if we are asking it to be stored.

Implementations§

Source§

impl GitCredential

Source

pub fn from_reader(source: impl Read) -> Result<GitCredential, Error>

Read the git-credential values from a Reader like stdin

use git_credential::GitCredential;

let s = "username=me\npassword=%sec&ret!\n\n".as_bytes();

let g = GitCredential::from_reader(s).unwrap();

assert_eq!(g.username.unwrap(), "me");
assert_eq!(g.password.unwrap(), "%sec&ret!");
Source

pub fn to_writer(&self, sink: impl Write) -> Result<(), Error>

Writes the git-credentials values to a Writer like stdout

use git_credential::GitCredential;

let mut g = GitCredential::default();
g.username = Some("me".into());
g.password = Some("%sec&ret!".into());

let mut v: Vec<u8> = Vec::new();

g.to_writer(&mut v).unwrap();

assert_eq!("username=me\npassword=%sec&ret!\n\n", String::from_utf8(v).unwrap());

Trait Implementations§

Source§

impl Debug for GitCredential

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GitCredential

Source§

fn default() -> GitCredential

Creates a new GitCredential struct with all values set to None

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,