aws_iot_device_sdk/lib.rs
1//! # Overview
2//!
3//! aws-iot-device-sdk (unofficial)
4//!
5//! The AWS IoT Device SDK is a collection of Rust source files,
6//! that can be used in embedded applications to securely connect IoT devices
7//! to [AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html).
8//!
9//! It contains ~~MQTT client, HTTP client, JSON Parser,~~ AWS IoT Device Shadow, AWS IoT Jobs,
10//! and AWS IoT Device Defender libraries.
11//!
12//! This SDK is distributed in source form, and can be built into customer firmware along with
13//! application code, other libraries and an operating system (OS) of your choice.
14//!
15//! These libraries are only dependent on pure Rust libraries, so they can be ported to various OS's - from embedded
16//! Real Time Operating Systems (RTOS) to Linux/Mac/Windows.
17//!
18//!
19//!
20// #![no_std]
21pub mod backoff_algo;
22pub mod common;
23pub mod defender;
24pub mod jobs;
25pub mod shadow;
26pub mod tunneling;
27
28pub use common::*;
29
30#[derive(Debug, PartialEq)]
31pub enum TopicType {
32 Other = 0,
33 NamedShadow,
34 Shadow,
35 Jobs,
36 Defender,
37 Tunneling,
38}
39/// Given the topic string of an incoming message, determine whether it is
40/// related to a device topic;
41///
42/// If it is, return the type of topic, like shadow ,jobs and so on.
43///
44/// # Example
45/// ```
46/// use aws_iot_device_sdk::{TopicType, match_topic_type};
47///
48/// let topic = "$aws/things/chloe/shadow/name/common/get/rejected";
49/// let topic_type = match_topic_type(topic).unwrap();
50///
51/// assert_eq!(topic_type, TopicType::NamedShadow);
52/// ```
53pub fn match_topic_type<'a>(topic: &'a str) -> Result<TopicType, Error> {
54 is_valid_mqtt_topic(topic)?;
55
56 let s = is_valid_prefix(topic, AWS_THINGS_PREFIX)?;
57
58 let mid = s.find('/').ok_or(Error::NoMatch);
59 let (thing_name, s) = s.split_at(mid?);
60 is_valid_thing_name(thing_name)?;
61 if s.starts_with(NAMED_SHADOW_API_BRIDGE) { Ok(TopicType::NamedShadow) }
62 else if s.starts_with(SHADOW_API_BRIDGE) { Ok(TopicType::Shadow) }
63 else if s.starts_with(JOBS_API_BRIDGE) { Ok(TopicType::Jobs) }
64 else if s.starts_with(DEFENDER_API_BRIDGE) { Ok(TopicType::Defender) }
65 else if s.starts_with(TUNNELS_API_BRIDGE) { Ok(TopicType::Tunneling) }
66 else { Err(Error::NoMatch) }
67}