1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pub use fluvio_controlplane_metadata::topic::*;
pub mod validate {
pub fn valid_topic_name(name: &str) -> bool {
name.chars()
.all(|ch| ch.is_ascii_lowercase() || ch.is_ascii_digit() || ch == '-')
&& !name.ends_with('-')
&& !name.starts_with('-')
}
#[cfg(test)]
mod tests {
use crate::topic::validate::valid_topic_name;
#[test]
fn reject_topics_with_spaces() {
assert!(!valid_topic_name("hello world"));
}
#[test]
fn reject_topics_with_uppercase() {
assert!(!valid_topic_name("helloWorld"));
}
#[test]
fn reject_topics_with_underscore() {
assert!(!valid_topic_name("hello_world"));
}
#[test]
fn valid_topic() {
assert!(valid_topic_name("hello-world"));
}
#[test]
fn reject_topics_that_start_with_hyphen() {
assert!(!valid_topic_name("-helloworld"));
}
}
}
mod convert {
use crate::CreatableAdminSpec;
use crate::DeletableAdminSpec;
use crate::objects::CreateFrom;
use crate::objects::DeleteRequest;
use crate::objects::ListRequest;
use crate::objects::ListResponse;
use crate::{AdminSpec, NameFilter};
use crate::objects::{ObjectFrom, ObjectTryFrom, Metadata, WatchResponse, WatchRequest};
use super::TopicSpec;
impl AdminSpec for TopicSpec {
type ListFilter = NameFilter;
type ListType = Metadata<Self>;
type WatchResponseType = Self;
}
impl CreatableAdminSpec for TopicSpec {
const CREATE_TYPE: u8 = 0;
}
impl DeletableAdminSpec for TopicSpec {
type DeleteKey = String;
}
CreateFrom!(TopicSpec, Topic);
ObjectFrom!(WatchRequest, Topic);
ObjectFrom!(WatchResponse, Topic);
ObjectFrom!(ListRequest, Topic);
ObjectFrom!(ListResponse, Topic);
ObjectFrom!(DeleteRequest, Topic);
ObjectTryFrom!(WatchResponse, Topic);
ObjectTryFrom!(ListResponse, Topic);
}