pub async fn open(
        root: impl AsRef<Path>,
        crate_name: impl Into<String>,
    ) -> Result<Self, IoError> {
        let crate_name = crate_name.into();
        let path = root.as_ref().join(get_path(&crate_name));

        create_parents(&path).await?;

        let file = open_file(&path).await?;

        let mut lines = BufReader::new(&file).lines();

        let mut entries = BTreeMap::new();

        while let Some(line) = lines.next().await {
            let line = line?;
            let metadata: Record = serde_json::from_str(&line).expect("JSON encoding error");
            entries.insert(metadata.version().clone(), metadata);
        }

        Ok(Self {
            crate_name,
            file,
            entries,
        })
    }
/// Open an existing file, or create a new one if it doesn't exist.
///
/// For convenience, this method will also create the parent folders in the
/// index if they don't yet exist.
Open an existing file, or create a new one if it doesn't exist.
For convenience, this method will also create the parent folders in the
index if they don't yet exist.
Open an existing file or create a new one if it doesn ' t exist . For convenience this method will also create the parent folders in the index if they don ' t yet exist .
pub async fn open(
        root: impl AsRef<Path>,
        crate_name: impl Into<String>,
    ) -> Result<Self, IoError> {
        let crate_name = crate_name.into();
        let path = root.as_ref().join(get_path(&crate_name));
        create_parents(&path).await?;
        let file = open_file(&path).await?;
        let mut lines = BufReader::new(&file).lines();
        let mut entries = BTreeMap::new();
        while let Some(line) = lines.next().await {
            let line = line?;
            let metadata: Record = serde_json::from_str(&line).expect("JSON encoding error");
            entries.insert(metadata.version().clone(), metadata);
        }
        Ok(Self {
            crate_name,
            file,
            entries,
        })
    }
pub async fn open ( root : impl AsRef < Path > , crate_name : impl Into < String > , ) -> Result < Self , IoError > { let crate_name = crate_name . into ( ) ; let path = root . as_ref ( ) . join ( get_path ( & crate_name ) ) ; create_parents ( & path ) . await ? ; let file = open_file ( & path ) . await ? ; let mut lines = BufReader :: new ( & file ) . lines ( ) ; let mut entries = BTreeMap :: new ( ) ; while let Some ( line ) = lines . next ( ) . await { let line = line ? ; let metadata : Record = serde_json :: from_str ( & line ) . expect ( " " ) ; entries . insert ( metadata . version ( ) . clone ( ) , metadata ) ; } Ok ( Self { crate_name , file , entries , } ) }
Open an existing file, or create a new one if it doesn't exist.
Open an existing file or create a new one if it doesn ' t exist .
root
impl AsRef<Path>
crate_name
impl Into<String>