Skip to main content

Module objects

Module objects 

Source
Expand description

Object storage buckets. Declared at module scope; resolved from the runtime on use.

use encore::objects::Bucket;

static UPLOADS: Bucket = Bucket::new("uploads");
static AVATARS: Bucket = Bucket::new("avatars").public().versioned();

Every operation is a method of the Bucket — upload, download, list, attrs, remove, … — named as in Encore’s TypeScript and Go SDKs. That is what lets Encore grant each service exactly the permissions it uses: the operation is visible at the call, so the parser can read it.

§References

For the same reason, a bucket cannot be passed around as a value. To hand it to other code, make a BucketRef, which grants only the permissions its type argument names:

use encore::objects::{perms, Bucket, Uploader};

static UPLOADS: Bucket = Bucket::named("uploads");

// Library code asks for the permissions it needs, as traits.
async fn save(bucket: &impl Uploader, key: &str) -> Result<(), encore::Error> {
    bucket.upload(key, b"hello".to_vec()).await?;
    Ok(())
}

async fn greet() -> Result<(), encore::Error> {
    save(&UPLOADS.reference::<perms::Uploader>(), "greeting.txt").await
}

The permissions are one of the perms, or a tuple of them ((perms::Uploader, perms::Lister)). Each has a trait of the same name here, with the methods it grants. Library code takes the traits — &impl Uploader, &(impl Uploader + Lister) — so it works with any reference that grants them, and can be tested against a fake.

Modules§

perms
The permissions a BucketRef can grant, as types for its type argument. Each has a trait of the same name in objects, with the methods it grants.

Structs§

AttrsOptions
Re-exported option and result types of the bucket operations.
Bucket
An object-storage bucket.
BucketRef
A reference to a Bucket that grants only the permissions P, made by Bucket::reference. Copy, and free to pass to other code.
ByteRange
Re-exported option and result types of the bucket operations. A contiguous byte range within an object.
Download
The contents of an object, as they arrive: returned by Bucket::download_stream. Take them chunk by chunk with Download::next — or as a Stream — all at once with Download::bytes, or as an AsyncRead with Download::into_async_read.
DownloadOptions
Re-exported option and result types of the bucket operations.
ExistsOptions
Re-exported option and result types of the bucket operations.
ListEntry
Re-exported option and result types of the bucket operations.
ListIterator
The objects of a bucket, as they are listed: returned by Bucket::list. Take them one at a time with ListIterator::next, or as a Stream.
ListOptions
Re-exported option and result types of the bucket operations.
ObjectAttrs
Re-exported option and result types of the bucket operations.
RemoveOptions
Re-exported option and result types of the bucket operations.
SignedDownloadUrl
A URL through which anyone holding it can download an object, made by Bucket::signed_download_url.
SignedUploadUrl
A URL through which anyone holding it can upload an object, made by Bucket::signed_upload_url.
SignedUrlOptions
Options for a signed URL.
UploadOptions
Re-exported option and result types of the bucket operations.
UploadPreconditions
Re-exported option and result types of the bucket operations.

Traits§

Attrser
Read objects’ attributes, and whether they exist. Implemented by a BucketRef granting perms::Attrser.
BucketPerms
A set of bucket permissions: one of the perms, or a tuple of them, which grants what any of its members does. Sealed: the SDK’s permissions are the only ones.
Downloader
Download objects. Implemented by a BucketRef granting perms::Downloader.
Lister
List objects. Implemented by a BucketRef granting perms::Lister.
PublicUrler
Resolve objects’ public URLs. Implemented by a BucketRef granting perms::PublicUrler.
ReadWriter
Every permission but PublicUrler. Implemented by whatever implements them all, such as a BucketRef granting perms::ReadWriter.
Remover
Remove objects. Implemented by a BucketRef granting perms::Remover.
SignedDownloader
Make signed download URLs. Implemented by a BucketRef granting perms::SignedDownloader.
SignedUploader
Make signed upload URLs. Implemented by a BucketRef granting perms::SignedUploader.
Uploader
Upload objects. Implemented by a BucketRef granting perms::Uploader.