Skip to main content

Crate renamed

Crate renamed 

Source
Expand description

§renamed

Official Rust SDK for the renamed.to API.

This crate provides a type-safe, async client for AI-powered document renaming, PDF splitting, and data extraction.

§Quick Start

use renamed::{RenamedClient, RenameOptions};

#[tokio::main]
async fn main() -> Result<(), renamed::RenamedError> {
    // Create a client with your API key
    let client = RenamedClient::new("rt_your_api_key");

    // Check your credits
    let user = client.get_user().await?;
    println!("Credits remaining: {}", user.credits.unwrap_or(0));

    // Rename a file using AI
    let result = client.rename("invoice.pdf", None).await?;
    println!("Suggested name: {}", result.suggested_filename);

    Ok(())
}

§Features

  • Rename: AI-powered file renaming based on content analysis
  • PDF Split: Split multi-page PDFs into separate documents
  • Extract: Extract structured data from documents

§Error Handling

All methods return Result<T, RenamedError>. The error type provides specific variants for different failure modes:

use renamed::{RenamedClient, RenamedError};

let client = RenamedClient::new("rt_your_api_key");

match client.get_user().await {
    Ok(user) => println!("Hello, {}!", user.email),
    Err(RenamedError::Authentication { .. }) => {
        eprintln!("Invalid API key");
    }
    Err(RenamedError::InsufficientCredits { .. }) => {
        eprintln!("Please add more credits");
    }
    Err(RenamedError::RateLimit { retry_after, .. }) => {
        if let Some(seconds) = retry_after {
            eprintln!("Rate limited. Retry after {} seconds", seconds);
        }
    }
    Err(e) => eprintln!("Error: {}", e),
}

§Async Jobs

Some operations like PDF splitting are asynchronous. These return an AsyncJob that can be polled for completion:

use renamed::{RenamedClient, PdfSplitOptions, SplitMode};

let client = RenamedClient::new("rt_your_api_key");

// Start the job
let job = client.pdf_split("multi-page.pdf", None).await?;

// Wait for completion with progress updates
let result = job.wait(Some(Box::new(|status| {
    println!("Progress: {}%", status.progress.unwrap_or(0));
}))).await?;

// Process the results
for doc in result.documents {
    let content = client.download_file(&doc.download_url).await?;
    tokio::fs::write(&doc.filename, content).await?;
}

§Configuration

Use the builder pattern for custom configuration:

use renamed::RenamedClient;
use std::time::Duration;

let client = RenamedClient::builder("rt_your_api_key")
    .timeout(Duration::from_secs(60))
    .max_retries(3)
    .build();

Modules§

prelude
Prelude module for convenient imports.

Structs§

AsyncJob
Represents an asynchronous job that can be polled for completion.
ExtractOptions
Options for the extract operation.
ExtractResult
Result of an extract operation.
JobStatusResponse
Response from the job status endpoint.
PdfSplitOptions
Options for PDF split operation.
PdfSplitResult
Result of a PDF split operation.
RenameOptions
Options for the rename operation.
RenameResult
Result of a rename operation.
RenamedClient
The main client for interacting with the renamed.to API.
RenamedClientBuilder
Builder for configuring a RenamedClient.
SplitDocument
A single document from a PDF split operation.
Team
Team information.
User
User profile information.

Enums§

JobStatus
Status of an async job.
RenamedError
The main error type for the renamed.to SDK.
SplitMode
Mode for PDF splitting.

Type Aliases§

ProgressCallback
A callback function that receives progress updates during job polling.
Result
Type alias for Results using RenamedError.