You are viewing the documentation for Deformable v0.8.0, an older version. Read the latest, v0.9.0

Rust API Reference

License

The license state of this device, or of this program under an Application license, and the calls that refresh it, sign in to a subscription, and activate and deactivate a license.

On this page

The license: its state, and the calls that refresh it, sign in to a subscription, and activate and deactivate a license. Nothing ever refuses to run: without a subscription or a license, Free runs, and a scene simulates at most 2,500 tetrahedrons. Three ways lift the limit: the Standalone subscription the person signs in to, the Standalone license of this device and user, and the Application license that a program activates for itself. A license failure’s message is written to show the user as it is, such as “Free: this would simulate 3,000 tetrahedrons; the limit is 2,500 per scene”.

start_sign_in starts a sign-in to a Standalone subscription: it gives a SignIn whose code the person approves in their browser, and wait_for_sign_in waits for that approval, then takes this device’s seat. take_over moves the seat to this device from the one using it, and sign_out frees the seat and forgets the sign-in. activate takes both kinds of key. A Standalone key is activated online once and stays on the device; the library keeps one Standalone state per device and user, shared by every program that loads it: the plugins and the SDKs. An Application key is checked offline and holds for the process only, so a program activates it at every start, before any other engine call; with it, the other calls contact nothing, and a plugin host refuses it. status never contacts the licensing service and is cheap enough to call on every redraw. The other calls wait on the network for at most their timeout, so a host with an interface calls them off its interface thread. set_online_access keeps a process off the network when its user asked for that.

  • The Standalone subscription runs on 1 device. The person signs in with their account in the browser (start_sign_in, then wait_for_sign_in until it gives a state); the sign-in and the lease our licensing service signs for this device belong to this device and user, and every program that loads the library shares them. refresh renews it, take_over uses it on this device instead of another, and sign_out frees the seat. The lease renews on its own while the engine runs, and a device may stay offline up to 1 day.
  • The Standalone license runs on 1 device per seat. Its key and the lease our licensing service signs for this device belong to this device and user, and every program that loads the library shares them; activate, refresh and deactivate activate, renew and deactivate it. The lease renews on its own while the engine runs, and a device may stay offline up to 7 days. A device holds a subscription or a license, not both.
  • The Application license is a company’s, for one app it ships. Its key is checked offline and licenses the program that activates it, on any device, for as long as it runs: nothing is stored or sent, so the app activates its key at every start, as its first Deformable call, before status and refresh, and its users need nothing. The plugins refuse an Application key.

ErrorKind::is_license tells a license failure, such as ErrorKind::TetrahedronLimitExceeded or ErrorKind::LicenseKeyRejected, from the others.

LicenseState

Enum · deformable::license::LicenseState

rust
pub enum LicenseState {
    Free,
    StandaloneSubscription,
    SubscriptionNeedsOnline,
    SubscriptionNoSeat,
    NoSubscription,
    SignInEnded,
    StandaloneLicense,
    LicenseNeedsOnline,
    Development,
    ApplicationTrial,
    ApplicationTrialEnded,
    ApplicationLicense,
    Unrecognized(i32),
}

The license state of this program, as LicenseStatus::state reports it: its Application license, or else the Standalone subscription, the Standalone license or Free of this device and user, which every program that loads the library shares.

Values

  • FreeNo license key and no sign-in: Free, at most LicenseStatus::tetrahedron_limit (2,500) tetrahedrons per scene.
  • StandaloneSubscriptionSigned in to a Standalone subscription, and this device holds a seat whose lease licenses it; no limit.
  • SubscriptionNeedsOnlineSigned in, but no subscription lease licenses this device now: it lapsed, this device’s clock leaves it untrusted, or the first seat could not be taken. Free runs until the next renewal online.
  • SubscriptionNoSeatSigned in, but this device holds no seat: another device took it over, it was removed, or every seat is in use. Free runs; a host offers to use the subscription here instead (take_over).
  • NoSubscriptionSigned in, but the account has no active Standalone subscription: Free runs.
  • SignInEndedThe licensing service no longer accepts the stored sign-in: Free runs until the person signs in again.
  • StandaloneLicenseA Standalone license key with a lease that licenses this device; no limit.
  • LicenseNeedsOnlineA Standalone license key whose lease ran out, or that this device’s clock leaves untrusted: Free runs until the next renewal online.
  • DevelopmentA development build of the library: licensing is off, no limit, and nothing contacts the licensing service. It is not the Application license.
  • ApplicationTrialAn Application trial key runs in this program: no limit, until the key ends.
  • ApplicationTrialEndedThe Application trial key of this program ended: Free runs.
  • ApplicationLicenseA full Application license key runs in this program; no limit.
  • Unrecognized (i32)A state this crate does not know, from a newer library.

Implements Clone · Copy · Debug · Eq · Hash · PartialEq · Send · Sync

See also Guide: License · C DeformableLicenseState · Python LicenseState

LicenseStatus

Struct · deformable::license::LicenseStatus

rust
pub struct LicenseStatus {
    pub state: LicenseState,
    pub days_left: u32,
    pub tetrahedron_limit: Option<u32>,
    pub has_license_key: bool,
    pub signed_in: bool,
    pub account: Option<String>,
    pub message: String,
}

The license state as a status line shows it.

Fields

  • state (LicenseState)Which license state the program is in; the other fields detail it.
  • days_left (u32)In LicenseState::ApplicationTrial, the whole days until the trial key ends counting the current day, 30 down to 1 for a 30-day key; 0 in any other state.
  • tetrahedron_limit (Option<u32>)The most tetrahedrons one scene simulates: 2,500 under Free and every state that falls back to it; None when there is no limit.
  • has_license_key (bool)A Standalone license key is stored on this device, so a host offers Deactivate rather than Activate; never under an Application license.
  • signed_in (bool)A Standalone subscription sign-in is stored on this device, so a host offers Sign Out; in LicenseState::SignInEnded it offers Sign In again too. Never under an Application license.
  • account (Option<String>)The email of the signed-in account; None when not signed in, when it could not be read yet, under an Application license and in a development build.
  • message (String)The status line: “Free: up to 2,500 tetrahedrons per scene”, “Standalone subscription”, “Standalone license”, “Application trial: 30 days left”, “Application license: Acme Inc.”, … A device or company name in it is cut to fit.

Implements Clone · Debug · Eq · PartialEq · Send · Sync

See also Guide: License · C DeformableLicenseStatus · Python LicenseStatus

SignIn

Struct · deformable::license::SignIn

rust
pub struct SignIn {
    pub user_code: String,
    pub verification_url: String,
    pub expires_in: Duration,
}

A sign-in to a Standalone subscription in progress, as start_sign_in gives it: what the host shows, and how long the code lasts.

Fields

  • user_code (String)The code to approve in the browser, such as ABCD-EFGH.
  • verification_url (String)The page that approves it with the code filled in; the host opens it in the browser.
  • expires_in (Duration)How long the code lasts from now, in whole seconds.

Implements Clone · Debug · Eq · PartialEq · Send · Sync

See also Guide: License · C DeformableSignIn · Python SignIn

status

Function · deformable::license::status

rust
pub fn status() -> Result<LicenseStatus, Error>

The license state of this program: its Application license, or else the Standalone subscription, the Standalone license or Free of this device and user. It never contacts the licensing service and never waits on the network: it reads the per-user license store at most once every 2 seconds, so it is cheap enough to call on every redraw.

Errors

  • Only the failures every call can give, which the conventions describe.

Example

rust
let status = deformable::license::status()?;
if let Some(limit) = status.tetrahedron_limit {
    println!("{} ({limit} per scene)", status.message);
}

See also Guide: License · C deformable_license_status · Python license.status

DEFAULT_TIMEOUT

Constant · deformable::license::DEFAULT_TIMEOUT

rust
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(15);

How long the calls that contact the licensing service wait for it when the host has no reason to choose otherwise: 15 seconds. The library counts anything above 60 seconds as 60 seconds.

See also Guide: License · Python license.DEFAULT_TIMEOUT

refresh

Function · deformable::license::refresh

rust
pub fn refresh(timeout: Duration) -> Result<LicenseStatus, Error>

Renews the stored Standalone key’s lease when it no longer licenses this device, or when it is 6 hours old or ends within a day and no contact ran in the last 5 minutes, waiting at most timeout. With a Standalone subscription instead, renews its lease when no contact ran in the last 5 minutes, so a seat taken over or removed, or a subscription that ended, shows at once; without a current lease or a seat, renews it or takes a free seat whatever the last contact was, never one another device holds. Under Free, after the sign-in ended, and under an Application license, nothing is sent and it gives the state as it is. The library renews a lease on its own while the engine runs, so a host calls this when the program starts and when its user asks.

It waits on the network, so a host with an interface calls it off its interface thread. Contacts run one at a time per process: a second caller waits for the first.

Parameters

  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds.

Returns

LicenseStatus: The license state after the call. After a failure, status gives the state to show.

Errors

  • LicenseServiceUnavailableThe service could not be reached or did not answer, its answer did not verify or this device’s clock contradicts it, or set_online_access forbade every contact. The lease is kept until it runs out.
  • LicenseKeyRejectedThe service no longer accepts the key: it was revoked or refunded, or this device was removed. The license is then forgotten at once and Free runs.
  • LicenseSignInFailedThe service could not read the request. A subscription that gives this device no seat is no error: the state says it.
  • LicenseStorageFailedThe per-user license store could not be written; the message names its folder.

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT};

let status = license::refresh(DEFAULT_TIMEOUT)?;
println!("{}", status.message);

See also Guide: License · C deformable_license_refresh · Python license.refresh

start_sign_in

Function · deformable::license::start_sign_in

rust
pub fn start_sign_in(timeout: Duration) -> Result<SignIn, Error>

Starts a sign-in to a Standalone subscription in the browser, waiting at most timeout for the licensing service: the host shows SignIn::user_code and opens SignIn::verification_url, where the person approves it, then calls wait_for_sign_in until it gives a state. Starting again replaces the sign-in this program started before. It waits on the network, so a host with an interface calls it off its interface thread.

Parameters

  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds.

Returns

SignIn: The code to show, the page to open and how long the code lasts.

Errors

  • InvalidArgumentA Standalone key is stored on this device (“Deactivate the current license first”), a sign-in is stored, except in LicenseState::SignInEnded (“Sign out of the Standalone subscription first”), or the program uses an Application license.
  • LicenseSignInFailedThis version of the library may not sign in, or the service could not read the request.
  • LicenseServiceUnavailableThe service could not be reached or did not answer, set_online_access forbade every contact, or licensing is off in a development build of the library.

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT};

match license::start_sign_in(DEFAULT_TIMEOUT) {
    Ok(sign_in) => println!(
        "Open {} and approve the code {}",
        sign_in.verification_url, sign_in.user_code
    ),
    Err(error) => println!("{}", error.message()),
}

See also Guide: License · C deformable_license_start_sign_in · Python license.start_sign_in

wait_for_sign_in

Function · deformable::license::wait_for_sign_in

rust
pub fn wait_for_sign_in(
    timeout: Duration,
) -> Result<Option<LicenseStatus>, Error>

Waits at most timeout for the person to approve the sign-in start_sign_in started, polling the licensing service as often as it allows, then takes this device a free seat of the subscription. It never returns before timeout without an answer, so a host loop of short waits does not spin, and it may return up to 25 seconds after it: a poll already sent is given 10 seconds to answer, and once approved, the seat is given 15 seconds of its own. A host runs it off its interface thread. A development build of the library has licensing off and gives its state at once.

Parameters

  • timeout (Duration)How long to wait for the approval, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds. 5 seconds suits a host loop that also watches for its user cancelling.

Returns

Option<LicenseStatus>: The license state once the account approved the sign-in, LicenseState::StandaloneSubscription when a seat was free; None while it has not yet.

Errors

Example

rust
use std::time::Duration;

use deformable::license;

let wait = Duration::from_secs(5);
let status = loop {
    if let Some(status) = license::wait_for_sign_in(wait)? {
        break status;
    }
};
println!("{}", status.message);

See also Guide: License · C deformable_license_wait_for_sign_in · Python license.wait_for_sign_in

take_over

Function · deformable::license::take_over

rust
pub fn take_over(timeout: Duration) -> Result<LicenseStatus, Error>

Uses the signed-in Standalone subscription on this device instead of another, waiting at most timeout: takes a free seat, or else the seat refreshed longest ago, whose device stops at its next check-in. A host offers it in LicenseState::SubscriptionNoSeat. It waits on the network, so a host with an interface calls it off its interface thread.

Parameters

  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds.

Returns

LicenseStatus: The license state after the call. After a license failure, status gives the state to show.

Errors

  • InvalidArgumentNo sign-in is stored, or the stored sign-in ended (“Sign in first”), a Standalone key is stored, or the program uses an Application license.
  • LicenseServiceUnavailableThe service could not be reached or did not answer, its answer did not verify or this device’s clock contradicts it, or set_online_access forbade every contact.
  • LicenseSignInFailedThe service could not read the request.
  • LicenseStorageFailedThe per-user license store could not be written; the message names its folder.

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT, LicenseState};

if license::status()?.state == LicenseState::SubscriptionNoSeat {
    let status = license::take_over(DEFAULT_TIMEOUT)?;
    println!("{}", status.message);
}

See also Guide: License · C deformable_license_take_over · Python license.take_over

sign_out

Function · deformable::license::sign_out

rust
pub fn sign_out(timeout: Duration) -> Result<LicenseStatus, Error>

Signs out of the Standalone subscription on this device at once, even offline, so Free runs; then frees this device’s seat and ends its session with the licensing service, waiting at most timeout. Without a sign-in, or under an Application license, it does nothing and succeeds. It waits on the network, so a host with an interface calls it off its interface thread.

Parameters

  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds.

Returns

LicenseStatus: The license state after the sign-out. After a failure, status gives the state to show.

Errors

  • LicenseServiceUnavailableThe seat could not be freed: the service could not be reached, or set_online_access forbade every contact. The sign-in is forgotten here all the same, and the seat frees itself within a day.
  • LicenseStorageFailedThe per-user license store could not be changed; the message names its folder.

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT};

let status = license::sign_out(DEFAULT_TIMEOUT)?;
assert!(!status.signed_in);

See also Guide: License · C deformable_license_sign_out · Python license.sign_out

activate

Function · deformable::license::activate

rust
pub fn activate(
    license_key: &str,
    timeout: Duration,
) -> Result<LicenseStatus, Error>

Activates license_key, a Standalone or an Application license key, told apart by their shape: a Standalone key is tgdfp-xxxxx-xxxxx-xxxxx-xxxxx, an Application key tgdfp-<payload hex>-<signature hex>.

A Standalone key is activated on this device with the licensing service, waiting at most timeout; the state is then LicenseState::StandaloneLicense. The key already stored here renews its lease instead. It waits on the network, so a host with an interface calls it off its interface thread.

An Application key is checked offline, without waiting, and licenses this program for as long as it runs: nothing is stored or sent, so the program calls this at every start, as its first Deformable call, before status and refresh. The state is then LicenseState::ApplicationLicense, or LicenseState::ApplicationTrial for a trial key. The same key again changes nothing. A full key covers the versions of the library released until its updates end, and keeps working in them forever. The plugins refuse an Application key. A development build of the library checks the key the same way but stays LicenseState::Development.

The error’s message says why the key was not activated, written to show the user as it is.

Parameters

  • license_key (&str)The license key, where letter case does not matter and spaces and line breaks are removed.
  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds. An Application key never waits.

Returns

LicenseStatus: The license state after the activation. After a license failure, status gives the state to show.

Errors

  • InvalidArgumentlicense_key is no license key or an Application key that does not verify; another Standalone key is stored on this device: deactivate it first; a Standalone subscription is signed in: sign out first; another Application key is already set in this program; or it is a Standalone key in a program on an Application license. Nothing changes then.
  • LicenseKeyRejectedThe service refused the Standalone key: it does not exist, was revoked or refunded, is not for Deformable, or every seat of the license is in use. Or the Application key was revoked, is a trial key that ended, covers only versions released before this one, or was given inside a plugin host.
  • LicenseServiceUnavailableThe service could not be reached or did not answer, its answer did not verify or this device’s clock contradicts it, or set_online_access forbade every contact.
  • LicenseStorageFailedThe per-user license store could not be written; the message names its folder.

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT};

let key = "tgdfp-xxxxx-xxxxx-xxxxx-xxxxx";
match license::activate(key, DEFAULT_TIMEOUT) {
    Ok(status) => println!("{}", status.message),
    Err(error) => println!("{}", error.message()),
}

// An app on an Application license activates its key, exactly as
// copied from the Licenses page, first thing at every start.
// This one is shaped like an Application key but signed by
// nobody, so it is refused.
let payload = "7b2276657273696f6e223a317d";
let application_key = format!("tgdfp-{payload}-{}", "0".repeat(128));
let result = license::activate(&application_key, DEFAULT_TIMEOUT);
if let Err(error) = result {
    eprintln!("{}", error.message());
}

See also Guide: License · C deformable_license_activate · Python license.activate

deactivate

Function · deformable::license::deactivate

rust
pub fn deactivate(timeout: Duration) -> Result<LicenseStatus, Error>

Forgets the Standalone license on this device at once, even offline, so Free runs; then frees its seat with the licensing service, waiting at most timeout, so the key can be activated on another device. When the seat cannot be freed, the customer removes this device on the Licenses page. With no key stored, or under an Application license, it does nothing and succeeds. It waits on the network, so a host with an interface calls it off its interface thread.

Parameters

  • timeout (Duration)How long to wait for the service, rounded up to whole milliseconds and at least 1 millisecond. The library counts anything above 60 seconds as 60 seconds.

Returns

LicenseStatus: The license state after the deactivation. After a failure, status gives the state to show.

Errors

Example

rust
use deformable::license::{self, DEFAULT_TIMEOUT};

let status = license::deactivate(DEFAULT_TIMEOUT)?;
assert!(!status.has_license_key);

See also Guide: License · C deformable_license_deactivate · Python license.deactivate

set_online_access

Function · deformable::license::set_online_access

rust
pub fn set_online_access(allowed: bool) -> Result<(), Error>

Allows (the default) or forbids every contact with the licensing service from this process, for a host whose user turned online access off. Forbidden, nothing is sent: refresh, start_sign_in, wait_for_sign_in, take_over and activate fail with ErrorKind::LicenseServiceUnavailable and change nothing, sign_out and deactivate forget the sign-in or license without freeing its seat, and the library never renews a lease on its own, so it runs out as it would offline. An Application key is checked offline and is not affected. It grants nothing, and it fails only when the library fails inside.

Parameters

  • allowed (bool)true allows every contact, false forbids them.

Errors

  • Only the failures every call can give, which the conventions describe.

Example

rust
// The user turned online access off in the host's settings.
deformable::license::set_online_access(false)?;

See also Guide: License · C deformable_license_set_online_access · Python license.set_online_access