Struct rust_car::unixfs::Link

source ·
pub struct Link { /* private fields */ }

Implementations§

source

pub fn new(hash: Cid, name: String, tsize: u64) -> Self

source

pub fn hash(&self) -> Cid

Examples found in repository?
examples/cat_cid.rs (line 28)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    // let cid = std::env::args().nth(1).expect("use cid as argument");
    let cid = "bafkreiaqv66m5nd6mwgkk7h5lwqnjzj54s4f7knmnrjhb7ylzqfg2vdo54";
    let file = std::path::Path::new("test");
    let file = file.join("carv1-basic.car");
    let file = std::fs::File::open(file).unwrap();
    let mut reader = reader::new_v1(file).unwrap();
    let roots = reader.header().roots();
    let file_cid = Cid::try_from(cid).expect("cid format error");
    for r in roots.iter() {
        let root_ipld = reader.ipld(r).unwrap();
        let root: Result<UnixFs, CarError> = root_ipld.try_into();
        let root_dir = root.unwrap();
        let count = root_dir
            .links()
            .iter()
            .filter(|u| u.hash() == file_cid)
            .count();
        if count > 0 {
            cat_ipld(&mut reader, file_cid).unwrap();
        }
    }
}
More examples
Hide additional examples
examples/ls.rs (line 29)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn walk(vecq: &mut VecDeque<Cid>, reader: &mut impl CarReader) {
    let mut cache: HashMap<Cid, String> = HashMap::new();
    let raw_code: u64 = RawCodec.into();
    while let Some(file_cid) = vecq.pop_front() {
        let codec = file_cid.codec();
        let file_n = cache.get(&file_cid).map_or(file_cid.to_string(), |c| c.to_string());
        println!("{file_n}");
        if codec == raw_code {
            continue;
        }
        let file_ipld: Ipld = reader.ipld(&file_cid).unwrap();
        match file_ipld {
            m @ Ipld::Map(_) => {
                let unixfs: UnixFs = m.try_into().unwrap();
                match unixfs.file_type() {
                    FileType::Directory => {},
                    _=> continue,
                }
                for n in unixfs.links().into_iter() {
                    let cid = n.hash();
                    cache.insert(cid, file_n.clone() + "/" + n.name_ref());
                    vecq.push_back(cid);
                }
            }
            _ => {}
        }
    }
}
source

pub fn name_ref(&self) -> &str

Examples found in repository?
examples/ls.rs (line 30)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn walk(vecq: &mut VecDeque<Cid>, reader: &mut impl CarReader) {
    let mut cache: HashMap<Cid, String> = HashMap::new();
    let raw_code: u64 = RawCodec.into();
    while let Some(file_cid) = vecq.pop_front() {
        let codec = file_cid.codec();
        let file_n = cache.get(&file_cid).map_or(file_cid.to_string(), |c| c.to_string());
        println!("{file_n}");
        if codec == raw_code {
            continue;
        }
        let file_ipld: Ipld = reader.ipld(&file_cid).unwrap();
        match file_ipld {
            m @ Ipld::Map(_) => {
                let unixfs: UnixFs = m.try_into().unwrap();
                match unixfs.file_type() {
                    FileType::Directory => {},
                    _=> continue,
                }
                for n in unixfs.links().into_iter() {
                    let cid = n.hash();
                    cache.insert(cid, file_n.clone() + "/" + n.name_ref());
                    vecq.push_back(cid);
                }
            }
            _ => {}
        }
    }
}
source

pub fn tsize(&self) -> u64

source

pub fn guess_type(&self) -> FileType

Trait Implementations§

source§

fn clone(&self) -> Link

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

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

fn default() -> Link

Returns the “default value” for a type. Read more
source§

fn eq(&self, other: &Link) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
const: unstable · source§

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

Mutably borrows from an owned value. Read more
const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

const: unstable · 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.

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
§

type Output = T

Should always be Self
§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.