fn build()

in core/src/services/huggingface/backend.rs [133:202]


    fn build(self) -> Result<impl Access> {
        debug!("backend build started: {:?}", &self);

        let repo_type = match self.config.repo_type.as_deref() {
            Some("model") => Ok(RepoType::Model),
            Some("dataset") => Ok(RepoType::Dataset),
            Some("space") => Err(Error::new(
                ErrorKind::ConfigInvalid,
                "repo type \"space\" is unsupported",
            )),
            Some(repo_type) => Err(Error::new(
                ErrorKind::ConfigInvalid,
                format!("unknown repo_type: {}", repo_type).as_str(),
            )
            .with_operation("Builder::build")
            .with_context("service", Scheme::Huggingface)),
            None => Ok(RepoType::Model),
        }?;
        debug!("backend use repo_type: {:?}", &repo_type);

        let repo_id = match &self.config.repo_id {
            Some(repo_id) => Ok(repo_id.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "repo_id is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Huggingface)),
        }?;
        debug!("backend use repo_id: {}", &repo_id);

        let revision = match &self.config.revision {
            Some(revision) => revision.clone(),
            None => "main".to_string(),
        };
        debug!("backend use revision: {}", &revision);

        let root = normalize_root(&self.config.root.unwrap_or_default());
        debug!("backend use root: {}", &root);

        let token = self.config.token.as_ref().cloned();

        Ok(HuggingfaceBackend {
            core: Arc::new(HuggingfaceCore {
                info: {
                    let am = AccessorInfo::default();
                    am.set_scheme(Scheme::Huggingface)
                        .set_native_capability(Capability {
                            stat: true,
                            stat_has_content_length: true,
                            stat_has_last_modified: true,

                            read: true,

                            list: true,
                            list_with_recursive: true,
                            list_has_content_length: true,
                            list_has_last_modified: true,

                            shared: true,

                            ..Default::default()
                        });
                    am.into()
                },
                repo_type,
                repo_id,
                revision,
                root,
                token,
            }),
        })
    }