Skip to content

Commit

Permalink
improve docs (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 7, 2022
1 parent febf070 commit c695a7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions git-refspec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Parse [ref specs]() and represent them.
//! Parse git ref-specs and represent them.
#![forbid(unsafe_code, rust_2018_idioms)]
#![allow(missing_docs)]
#![deny(missing_docs)]

///
pub mod parse;
pub use parse::function::parse;

Expand Down
2 changes: 2 additions & 0 deletions git-refspec/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// The error returned by the [`parse()`][crate::parse()] function.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Empty refspecs are invalid")]
Empty,
Expand Down
19 changes: 19 additions & 0 deletions git-refspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
use crate::types::Push;
use crate::{Fetch, Instruction, Mode, Operation, RefSpec, RefSpecRef};

/// Conversion. Use the [RefSpecRef][RefSpec::to_ref()] type for more usage options.
impl RefSpec {
/// Return ourselves as reference type.
pub fn to_ref(&self) -> RefSpecRef<'_> {
RefSpecRef {
mode: self.mode,
op: self.op,
src: self.src.as_ref().map(|b| b.as_ref()),
dst: self.dst.as_ref().map(|b| b.as_ref()),
}
}
}

impl Into<RefSpec> for RefSpecRef<'_> {
fn into(self) -> RefSpec {
self.to_owned()
}
}

/// Access
impl RefSpecRef<'_> {
/// Return the refspec mode.
Expand Down
6 changes: 6 additions & 0 deletions git-refspec/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ pub enum Operation {
Fetch,
}

/// Tells what to do and is derived from a [`RefSpec`][RefSpecRef].
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub enum Instruction<'a> {
/// An instruction for pushing.
Push(Push<'a>),
/// An instruction for fetching.
Fetch(Fetch<'a>),
}

Expand Down Expand Up @@ -56,6 +59,7 @@ pub enum Push<'a> {
/// Destinations can only be a partial or full ref-names on the local side.
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub enum Fetch<'a> {
/// Fetch a ref or refs and write the result into the `FETCH_HEAD` without updating local branches.
Only {
/// The ref name to fetch on the remote side, without updating the local side. This will write the result into `FETCH_HEAD`.
src: &'a BStr,
Expand All @@ -65,6 +69,7 @@ pub enum Fetch<'a> {
/// A single partial or full ref name to exclude on the remote, or a pattern with a single `*`. It cannot be a spelled out object hash.
src: &'a BStr,
},
/// Fetch from `src` and update the corresponding destination branches in `dst` accordingly.
AndUpdate {
/// The ref name to fetch on the remote side, or a pattern with a single `*` to match against.
src: &'a BStr,
Expand All @@ -77,6 +82,7 @@ pub enum Fetch<'a> {
}

impl Instruction<'_> {
/// Derive the mode of operation from this instruction.
pub fn operation(&self) -> Operation {
match self {
Instruction::Push(_) => Operation::Push,
Expand Down

0 comments on commit c695a7e

Please sign in to comment.