Skip to main content

Introducing Our New Rust SDK - Build Faster and Smarter

· 7 min read
Tímea Kopacz
I have approximate knowledge of many things.

Hey, Rustaceans! We developed the Rust SDK in response to a feature request from one of our customers, OneSignal. When we heard about their needs, we rolled up our sleeves and released the Rust SDK two months later. With it, you can manage feature flags like a pro—whether starting a new project or optimizing an existing app. It allows you to toggle features on and off without redeploying your code. That's right—no more redeploys every time your boss changes their mind about a button color!

With ConfigCat's feature flags, you can gradually roll out new features, rigorously test them (in a controlled environment, of course), and make changes on the fly—all directly from your dashboard! Let's dive into why this is a game-changer for your development workflow.

Introducing ConfigCat Rust SDK Cover

The Rust SDK in Action

With our shiny new Rust SDK, you can now wield the power of ConfigCat in your Rust-based applications. Rust is known for being fast, memory-safe, and just plain cool, so naturally, ConfigCat fits right in. Here's what you can do with this dynamic duo:

  • Roll out features safely: Think of it as releasing a feature into a controlled environment. Let a small group of users try it first. If it works well, you can roll it out to everyone.

  • A/B testing: Test different variations of a feature to see which one users like most. Use the results to make better decisions.

  • Instant configuration changes: Make configuration tweaks and changes from the ConfigCat dashboard without redeploying your app. This ensures there's no downtime and keeps your users happy.

  • Target specific users: Customize features for different user segments. For example, provide advanced features to your beta testers or premium users, while keeping things simple for others.

Why Rust and ConfigCat Are a Match Made in Developer Heaven

Rust is like the superhero of programming languages: it's fast, safe, and perfect for mission-critical apps. Now, add ConfigCat feature flags into the mix, and you've got a superpower that lets you change your app's behavior in real time without redeploying.

The ConfigCat Rust SDK lets you:

  • Control app behavior in real-time (yes, really).
  • Test and roll out new features without the heart-stopping fear of breaking everything.
  • Keep things snappy—because Rust wouldn't have it any other way.

Why Businesses Love Rust

Imagine you're a business that likes to keep things running smoothly—because, well, who doesn't? With the Rust SDK, your dev teams can innovate at lightning speed, releasing new features faster than a cat can chase a laser pointer.

Want to A/B test a feature? ConfigCat makes it easy. Launch different variations, see which one customers click more, and voilà—data-driven decisions, here you come. Plus, when something goes wrong (not that it ever does, right?), you can disable features with a click, without breaking a sweat (or your entire app). Make changes, test the waters, and roll back when needed—all with zero downtime. Your customers will barely notice a thing... except how awesome everything is working.

Rust has been rapidly gaining popularity among developers and businesses alike—and for good reason. Let's explore what sets Rust apart and why it could be an ideal choice for your next project:

1. Performance: Rust offers performance comparable to C and C++, thanks to its system-level control over memory and thread management. This makes it ideal for building high-performance applications where speed is crucial—think game engines, operating systems, and real-time services.

2. Memory safety without garbage collection: One of Rust's most lauded features is its ownership system, which ensures memory safety without a garbage collector. This means fewer runtime errors and a significant reduction in memory-related bugs like null pointer dereferences and buffer overflows, common in other languages.

3. Concurrency: Rust's ownership model also allows for fearless concurrency. You can write multi-threaded code without worrying about data races, which makes Rust an excellent choice for developing scalable, concurrent systems—something that's increasingly important in our multi-core processor world.

4. Developer productivity: Rust's tooling is top-notch, with an integrated package manager (Cargo), a robust compiler that provides helpful error messages, and a growing ecosystem of libraries and frameworks. This reduces development time and helps you get features into production faster.

5. Growing ecosystem: Rust has a rapidly expanding ecosystem and a passionate community, which means you're not alone when you choose Rust. Libraries and tools are continually being developed and improved, making it easier to integrate Rust into your existing systems.

6. Strong community and industry adoption: Rust has been voted the "most loved programming language" in Stack Overflow's annual developer survey for multiple years. Major companies like Mozilla, Dropbox, and Cloudflare have adopted Rust for critical parts of their infrastructure, citing its reliability and performance.

Getting Started with the ConfigCat Rust SDK

Rust's performance and reliability are legendary. Pair that with ConfigCat's feature flags, and you've got a winning combo that keeps your app lightning-fast while letting you manage features dynamically. Whether you're building web services, CLI tools, or even operating systems, ConfigCat's Rust SDK keeps you flexible, agile, and ready to handle anything that comes your way.

So, what are you waiting for? Let's get those feature flags flying!

1. Install the Package

First things first: install the ConfigCat Rust SDK into your project with following Cargo command:

cargo add configcat

Alternatively, add it directly to your Cargo.toml file:

[dependencies]
configcat = "0.1"

2. Import the ConfigCat Module

Now, import the ConfigCat module into your app:

use configcat::*;

3. Create the ConfigCat Client

Next, create the ConfigCat client with your SDK key. This client is your magic gateway to feature flag goodness:

use configcat::*;

#[tokio::main]
async fn main() {
let client = Client::new("#YOUR-SDK-KEY#").unwrap();
}
info

It is recommended to configure the ConfigCat client as a singleton within the application. For cases with multiple SDK keys, a separate ConfigCat client should be created for each key.

4. Fetch and Use Your Feature Flags

Now for the fun part! Fetch your feature flags with the get_value method. For example, let's check if the isAwesomeFeatureEnabled flag is on:

use configcat::*;

#[tokio::main]
async fn main() {
let client = Client::new("#YOUR-SDK-KEY#").unwrap();

let is_awesome_feature_enabled = client.get_value("isAwesomeFeatureEnabled", false, None).await;

if is_awesome_feature_enabled {
do_the_new_thing();
} else {
do_the_old_thing();
}
}

Customizing the Client

Feeling fancy? Customize the client using the builder pattern. Set polling intervals, data governance options, and more:

use std::time::Duration;
use configcat::{Client, PollingMode, DataGovernance};

let builder = Client::builder("#YOUR-SDK-KEY#")
.polling_mode(PollingMode::AutoPoll(Duration::from_secs(60)))
.data_governance(DataGovernance::EU);

let client = builder.build().unwrap();

Flag Overrides

You can override feature flags locally, like a boss. Here's how you can do it with a local JSON file:

use configcat::{Client, FileDataSource, OverrideBehavior};

let file_ds = FileDataSource::new("path/to/local_flags.json").unwrap();

let client = Client::builder("localhost")
.overrides(Box::new(file_ds), OverrideBehavior::LocalOnly)
.build()
.unwrap();

Now that you've got the basics, go forth and flag all the features. May your rollouts be smooth and your features forever awesome! To dive deeper, be sure to check out the Rust SDK to start integrating feature flags into your Rust projects right away.

Conclusion

ConfigCat's Rust SDK opens up a world of possibilities for Rust developers, allowing you to manage features with unparalleled flexibility and safety. By leveraging feature flags, you can introduce new functionality gradually, conduct A/B testing, and respond quickly to user feedback—all without the need to redeploy your application. This means faster iteration, fewer disruptions, and a smoother development process.

Rust's performance and safety, combined with ConfigCat's dynamic feature management, offer a powerful toolkit for any developer looking to build robust, scalable applications. Whether working on a cutting-edge project or maintaining an established system, ConfigCat's Rust SDK will help you move fast without breaking things. So why not give it a try? Install the SDK, set up your feature flags, and make your Rust applications even more awesome today. Happy coding!

If you want to stay up-to-date with the mischievous antics of the cat with feature flags, follow ConfigCat on X, Facebook, LinkedIn, and GitHub