iab-specs
An unofficial Rust implementation of various IAB (Interactive Advertising Bureau) specifications.
Overview
iab-specs provides typed Rust data structures for working with IAB advertising specifications. Rather than being just a parser, this library wraps each specification's logic into idiomatic Rust types using serde for serialization/deserialization and FromStr/Display for string conversions.
Currently Supported Specifications
- AdCOM 1.0 - Advertising Common Object Model (enumerations)
- OpenRTB 2.5 - Real-Time Bidding protocol
- OpenRTB 2.6 - Real-Time Bidding protocol with CTV/DOOH support
- OpenRTB 3.0 - Real-Time Bidding protocol with layered architecture
- Ads.txt 1.1 - Authorized Digital Sellers declaration for websites
- App-ads.txt 1.0 - Authorized Digital Sellers declaration for mobile and CTV apps
- Sellers.json 1.0 - Supply chain transparency
Installation
Add iab-specs to your Cargo.toml with the features you need:
[]
# Enable all specifications
= { = "0.2", = ["adcom", "openrtb_25", "openrtb_26", "openrtb_3", "ads_txt", "app_ads_txt", "sellers_json"] }
# Or enable only what you need
= { = "0.2", = ["openrtb_3"] }
Or use cargo:
# Enable all specifications
# Or enable only what you need
Features
⚠️ Important: By default, no features are enabled. You must explicitly enable the specifications you need.
The library uses cargo features to enable/disable specifications:
adcom- AdCOM 1.0 support (Advertising Common Object Model enumerations)openrtb_25- OpenRTB 2.5 support (automatically includesadcom)openrtb_26- OpenRTB 2.6 support (automatically includesopenrtb_25andadcom)openrtb_3- OpenRTB 3.0 support (automatically includesadcom)ads_txt- Ads.txt 1.1 supportapp_ads_txt- App-ads.txt 1.0 support (automatically includesads_txt)sellers_json- Sellers.json 1.0 support
Feature Selection Examples
[]
# Only AdCOM support
= { = "0.2", = ["adcom"] }
# Only OpenRTB 2.5 support (automatically includes adcom)
= { = "0.2", = ["openrtb_25"] }
# Only OpenRTB 2.6 support (automatically includes openrtb_25 and adcom)
= { = "0.2", = ["openrtb_26"] }
# Only OpenRTB 3.0 support (automatically includes adcom)
= { = "0.2", = ["openrtb_3"] }
# Only ads.txt support
= { = "0.2", = ["ads_txt"] }
# Only app-ads.txt support (automatically includes ads_txt)
= { = "0.2", = ["app_ads_txt"] }
# Only sellers.json support
= { = "0.2", = ["sellers_json"] }
# OpenRTB 3.0 with ads.txt and sellers.json
= { = "0.2", = ["openrtb_3", "ads_txt", "sellers_json"] }
# All specifications
= { = "0.2", = ["adcom", "openrtb_25", "openrtb_26", "openrtb_3", "ads_txt", "app_ads_txt", "sellers_json"] }
Why no default features?
This design allows you to:
- Minimize dependencies: Only include what you actually use
- Reduce compile time: Don't compile unused specifications
- Smaller binary size: Eliminate unused code from your final binary
- Explicit dependencies: Be clear about which IAB specs your project relies on
Quick Start
Creating an OpenRTB Bid Request
use ;
Using the Builder Pattern
For more ergonomic construction, use the builder pattern:
use ;
Usage Examples
AdCOM
Use standardized enumeration values from the Advertising Common Object Model:
use ;
// Auction types
let auction = FirstPrice;
assert_eq!;
// Device types
let device = Phone;
assert_eq!;
// API frameworks
let api = Mraid3;
assert_eq!;
// Video protocols
let protocol = Vast4;
assert_eq!;
OpenRTB 2.5 and 2.6
OpenRTB 2.5 and 2.6 are fully implemented with complete bid request/response objects.
Supply Chain Transparency
use ;
OpenRTB 2.6 Features
OpenRTB 2.6 adds support for CTV ad pods, DOOH multipliers, and more:
use ;
OpenRTB 3.0
OpenRTB 3.0 introduces a layered architecture with explicit versioning and supply chain transparency as a first-class feature:
use ;
use ;
Key OpenRTB 3.0 Features:
- Explicit protocol and domain versioning
- Supply chain transparency promoted to core object
- Item-based inventory (replaces Imp)
- Comprehensive tracking URLs (nurl, burl, lurl)
- Package bidding support
- Measurement metrics
OpenRTB 3.0 Documentation:
- Migration Guide - Migrate from 2.x to 3.0
- Usage Guide - Complete examples and patterns
- Best Practices - Production guidelines
Ads.txt
Parse and generate ads.txt files:
use ;
use FromStr;
// Parse an ads.txt file
let ads_txt_content = "google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0";
let ads_txt = from_str?;
// Create an ads.txt programmatically
let ads_txt = builder
.contact
.owner_domain
.systems
.build?;
// Serialize to string
let output = ads_txt.to_string;
App-ads.txt
Parse and generate app-ads.txt files for mobile and CTV applications:
use ;
use FromStr;
// Parse an app-ads.txt file
let app_ads_content = r#"
contact=monetization@mygame.com
subdomain=games.mygame.com
# Primary ad network
google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0
# Reseller partners
silverssp.com, 9876, RESELLER, f6578439
"#;
let app_ads = from_str?;
// Create an app-ads.txt programmatically
let app_ads = builder
.contact
.subdomain
.systems
.build?;
// Serialize to string
let output = app_ads.to_string;
Note on ads.txt 1.1 vs app-ads.txt 1.0:
App-ads.txt v1.0 is based on an earlier ads.txt specification and does not support the ads.txt 1.1 features:
OWNERDOMAIN(not in app-ads.txt v1.0)MANAGERDOMAIN(not in app-ads.txt v1.0)
Attempting to parse an app-ads.txt file containing these directives will result in an error.
Sellers.json
Parse and generate sellers.json files:
use ;
use FromStr;
// Parse a sellers.json file
let sellers_json = r#"{
"contact_email": "adops@example.com",
"version": "1.0",
"sellers": [
{
"seller_id": "12345",
"seller_type": "publisher",
"name": "Example Publisher",
"domain": "example.com"
}
]
}"#;
let sellers = from_str?;
// Create sellers.json programmatically
let sellers = builder
.contact_email
.version
.sellers
.build?;
// Serialize to JSON string
let output = to_string_pretty?;
Documentation
Full API documentation is available on docs.rs.
For usage examples, please refer to the unit tests in the source code. Each module includes comprehensive test cases demonstrating both serialization and deserialization.
Development
The project includes shell scripts for common development tasks:
Format Code
Check or fix code formatting with rustfmt:
Run Linter
Check code quality with clippy:
Run Tests
Run tests with configurable features:
Generate Coverage
Generate code coverage reports:
All scripts support --help for more options.
Roadmap
- AdCOM 1.0
- Ads.txt 1.1
- App-ads.txt 1.0
- Sellers.json 1.0
- OpenRTB 2.5
- OpenRTB 2.6
- OpenRTB 3.0
- Additional IAB specifications (contributions welcome!)
Contributing
Contributions are welcome! Whether it's:
- Adding new IAB specifications
- Improving existing implementations
- Fixing bugs
- Improving documentation
- Adding examples
Please see CONTRIBUTING.md for detailed guidelines on:
- Development setup
- Running tests locally with
act - Code coverage requirements
- Contribution workflow
License
Licensed under Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.