rice_stun_types/lib.rs
1// Copyright (C) 2025 Matthew Waters <matthew@centricular.com>
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#![deny(missing_debug_implementations)]
10#![deny(missing_docs)]
11
12//! # rice-stun-types
13//!
14//! Implementation of ICE-relevant STUN attributes based on [stun-types] as specified in [RFC8445],
15//! [RFC6544], and [RFC5245].
16//!
17//! ## Relevant standards
18//!
19//! - [x] [RFC5245]: Interactive Connectivity Establishment (ICE): A Protocol for Network Address
20//! Translator (NAT) Traversal for Offer/Answer Protocols
21//! - [x] [RFC6544]: TCP Candidates with Interactive Connectivity Establishment (ICE)
22//! - [x] [RFC8445]: Interactive Connectivity Establishment (ICE): A Protocol
23//! for Network Address Translator (NAT) Traversal
24//!
25//! [RFC5245]: <https://tools.ietf.org/html/rfc5245>
26//! [RFC6544]: <https://tools.ietf.org/html/rfc6544>
27//! [RFC8445]: <https://tools.ietf.org/html/rfc8445>
28//! [stun-types]: https://docs.rs/stun-types
29
30#![no_std]
31
32#[cfg(any(feature = "std", test))]
33extern crate std;
34
35pub mod attribute;
36
37/// Initialize some debugging functionality of the library.
38///
39/// It is not required to call this function, however doing so allows debug functionality of
40/// stun-types to print much more human readable descriptions of attributes and messages.
41pub fn debug_init() {
42 attribute::debug_init();
43}
44
45#[cfg(test)]
46pub(crate) mod tests {
47 use tracing::subscriber::DefaultGuard;
48 use tracing_subscriber::Layer;
49 use tracing_subscriber::layer::SubscriberExt;
50
51 use super::*;
52
53 pub fn test_init_log() -> DefaultGuard {
54 debug_init();
55 let level_filter = std::env::var("RICE_LOG")
56 .or(std::env::var("RUST_LOG"))
57 .ok()
58 .and_then(|var| var.parse::<tracing_subscriber::filter::Targets>().ok())
59 .unwrap_or(
60 tracing_subscriber::filter::Targets::new().with_default(tracing::Level::TRACE),
61 );
62 let registry = tracing_subscriber::registry().with(
63 tracing_subscriber::fmt::layer()
64 .with_file(true)
65 .with_line_number(true)
66 .with_level(true)
67 .with_target(false)
68 .with_test_writer()
69 .with_filter(level_filter),
70 );
71 tracing::subscriber::set_default(registry)
72 }
73}