Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(!): Allow users to build operator from config #4919

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Jul 24, 2024

Which issue does this PR close?

Part of #3240.

Rationale for this change

This adds Operator::from_config support so users can build operator from config directly:

use std::collections::HashMap;

use opendal::services::MemoryConfig;
use opendal::Operator;
async fn test() -> Result<()> {
    let mut cfg = MemoryConfig::default();
    cfg. root = Some("/".to_string());

    // Build an `Operator` to start operating the storage.
    let op: Operator = Operator::from_config(cfg)?.finish();

    Ok(())
}

We have to introduce a new trait Configurator since we can't infer B while given B::Config.

What changes are included in this PR?

New API Operator::from_config. This API also changed Builder:

- fn build(&mut self) -> Result<Self::Accessor>;
+ fn build(self) -> Result<impl Access>;

This change fixed long existed issues about reusing builder and lifetime.

Are there any user-facing changes?

This is breaking change PR.

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo merged commit a3ddda6 into main Jul 24, 2024
254 of 255 checks passed
@Xuanwo Xuanwo deleted the introduce-configurator branch July 24, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants