oxedyne/fe2o3/fe2o3_jdat/src/kind.rs
48.1 KiB, 22 runs
created by r1870400018:471, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use crate::{ |
| 2 | prelude::*, |
| 3 | usr::UsrKindId, |
| 4 | }; |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | |
| 8 | use std::fmt; |
| 9 | |
| 10 | |
| 11 | /// A lightweight twin of `Dat` without any included data, intended to keep string decoding a |
| 12 | /// bit simpler. All the variants of `Dat` should be included, with the addition of |
| 13 | /// Kind::None, which allows us to avoid wrapping in an `Option`. |
| 14 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] |
| 15 | pub enum Kind { |
| 16 | Unknown, // for id conversion |
| 17 | // Atomic Kinds =========================== |
| 18 | // Logic |
| 19 | Empty, |
| 20 | True, |
| 21 | False, |
| 22 | None, |
| 23 | // Fixed |
| 24 | U8, |
| 25 | U16, |
| 26 | U32, |
| 27 | U64, |
| 28 | U128, |
| 29 | I8, |
| 30 | I16, |
| 31 | I32, |
| 32 | I64, |
| 33 | I128, |
| 34 | F32, |
| 35 | F64, |
| 36 | // Variable |
| 37 | Aint, |
| 38 | Adec, |
| 39 | C64, |
| 40 | Str, |
| 41 | // Molecular Kinds ======================== |
| 42 | // Unitary |
| 43 | Usr(UsrKindId), |
| 44 | Box(Option<Box<Kind>>), |
| 45 | Some(Option<Box<Kind>>), |
| 46 | ABox(Option<Box<Kind>>), |
| 47 | // Heterogenous |
| 48 | List, |
| 49 | Tup2, |
| 50 | Tup3, |
| 51 | Tup4, |
| 52 | Tup5, |
| 53 | Tup6, |
| 54 | Tup7, |
| 55 | Tup8, |
| 56 | Tup9, |
| 57 | Tup10, |
| 58 | Map, |
| 59 | OrdMap, |
| 60 | // Homogenous |
| 61 | Vek, |
| 62 | // Variable length bytes |
| 63 | BU8, |
| 64 | BU16, |
| 65 | BU32, |
| 66 | BU64, |
| 67 | BC64, |
| 68 | // Fixed length bytes |
| 69 | B2, |
| 70 | B3, |
| 71 | B4, |
| 72 | B5, |
| 73 | B6, |
| 74 | B7, |
| 75 | B8, |
| 76 | B9, |
| 77 | B10, |
| 78 | B16, |
| 79 | B32, |
| 80 | // Variable length numbers |
| 81 | Vu16, // Not yet implemented |
| 82 | Vu32, // Not yet implemented |
| 83 | Vu64, // Not yet implemented |
| 84 | Vu128, // Not yet implemented |
| 85 | Vi8, // Not yet implemented |
| 86 | Vi16, // Not yet implemented |
| 87 | Vi32, // Not yet implemented |
| 88 | Vi64, // Not yet implemented |
| 89 | Vi128, // Not yet implemented |
| 90 | // Fixed length numbers |
| 91 | Tup2u8, |
| 92 | Tup3u8, |
| 93 | Tup4u8, |
| 94 | Tup5u8, |
| 95 | Tup6u8, |
| 96 | Tup7u8, |
| 97 | Tup8u8, |
| 98 | Tup9u8, |
| 99 | Tup10u8, |
| 100 | |
| 101 | Tup2u16, |
| 102 | Tup3u16, |
| 103 | Tup4u16, |
| 104 | Tup5u16, |
| 105 | Tup6u16, |
| 106 | Tup7u16, |
| 107 | Tup8u16, |
| 108 | Tup9u16, |
| 109 | Tup10u16, |
| 110 | |
| 111 | Tup2u32, |
| 112 | Tup3u32, |
| 113 | Tup4u32, |
| 114 | Tup5u32, |
| 115 | Tup6u32, |
| 116 | Tup7u32, |
| 117 | Tup8u32, |
| 118 | Tup9u32, |
| 119 | Tup10u32, |
| 120 | |
| 121 | Tup2u64, |
| 122 | Tup3u64, |
| 123 | Tup4u64, |
| 124 | Tup5u64, |
| 125 | Tup6u64, |
| 126 | Tup7u64, |
| 127 | Tup8u64, |
| 128 | Tup9u64, |
| 129 | Tup10u64, |
| 130 | |
| 131 | Tup2i8, |
| 132 | Tup3i8, |
| 133 | Tup4i8, |
| 134 | Tup5i8, |
| 135 | Tup6i8, |
| 136 | Tup7i8, |
| 137 | Tup8i8, |
| 138 | Tup9i8, |
| 139 | Tup10i8, |
| 140 | |
| 141 | Tup2i16, |
| 142 | Tup3i16, |
| 143 | Tup4i16, |
| 144 | Tup5i16, |
| 145 | Tup6i16, |
| 146 | Tup7i16, |
| 147 | Tup8i16, |
| 148 | Tup9i16, |
| 149 | Tup10i16, |
| 150 | |
| 151 | Tup2i32, |
| 152 | Tup3i32, |
| 153 | Tup4i32, |
| 154 | Tup5i32, |
| 155 | Tup6i32, |
| 156 | Tup7i32, |
| 157 | Tup8i32, |
| 158 | Tup9i32, |
| 159 | Tup10i32, |
| 160 | |
| 161 | Tup2i64, |
| 162 | Tup3i64, |
| 163 | Tup4i64, |
| 164 | Tup5i64, |
| 165 | Tup6i64, |
| 166 | Tup7i64, |
| 167 | Tup8i64, |
| 168 | Tup9i64, |
| 169 | Tup10i64, |
| 170 | |
| 171 | //// Scheduled for removal |
| 172 | //PartKey, |
| 173 | } |
| 174 | |
| 175 | impl Daticle for Dat { |
| 176 | |
| 177 | /// Establish mapping from a `Dat` to a `Kind`. |
| 178 | fn kind(&self) -> Kind { |
| 179 | match &*self { |
| 180 | // Atomic Kinds =========================== |
| 181 | // Logic |
| 182 | Self::Empty => Kind::Empty, |
| 183 | Self::Bool(b) => if *b { Kind::True } else { Kind::False }, |
| 184 | // Fixed |
| 185 | Self::U8(_) => Kind::U8, |
| 186 | Self::U16(_) => Kind::U16, |
| 187 | Self::U32(_) => Kind::U32, |
| 188 | Self::U64(_) => Kind::U64, |
| 189 | Self::U128(_) => Kind::U128, |
| 190 | Self::I8(_) => Kind::I8, |
| 191 | Self::I16(_) => Kind::I16, |
| 192 | Self::I32(_) => Kind::I32, |
| 193 | Self::I64(_) => Kind::I64, |
| 194 | Self::I128(_) => Kind::I128, |
| 195 | Self::F32(_) => Kind::F32, |
| 196 | Self::F64(_) => Kind::F64, |
| 197 | // Variable |
| 198 | Self::Aint(_) => Kind::Aint, |
| 199 | Self::Adec(_) => Kind::Adec, |
| 200 | Self::C64(_) => Kind::C64, |
| 201 | Self::Str(_) => Kind::Str, |
| 202 | // Molecular Kinds ======================== |
| 203 | // Unitary |
| 204 | Self::Usr(ukid, _optboxd) => Kind::Usr(ukid.clone()), |
| 205 | Self::Box(boxd) => Kind::Box(Some(Box::new((*boxd).kind()))), |
| 206 | Self::Opt(boxoptd) => match &**boxoptd { |
| 207 | None => Kind::None, |
| 208 | Some(d) => Kind::Some(Some(Box::new(d.kind()))), |
| 209 | }, |
| 210 | Self::ABox(_, boxd, _) => Kind::ABox(Some(Box::new((*boxd).kind()))), |
| 211 | // Heterogenous |
| 212 | Self::List(_) => Kind::List, |
| 213 | Self::Tup2(_) => Kind::Tup2, |
| 214 | Self::Tup3(_) => Kind::Tup3, |
| 215 | Self::Tup4(_) => Kind::Tup4, |
| 216 | Self::Tup5(_) => Kind::Tup5, |
| 217 | Self::Tup6(_) => Kind::Tup6, |
| 218 | Self::Tup7(_) => Kind::Tup7, |
| 219 | Self::Tup8(_) => Kind::Tup8, |
| 220 | Self::Tup9(_) => Kind::Tup9, |
| 221 | Self::Tup10(_) => Kind::Tup10, |
| 222 | Self::Map(_) => Kind::Map, |
| 223 | Self::OrdMap(_) => Kind::OrdMap, |
| 224 | // Homogenous |
| 225 | Self::Vek(_) => Kind::Vek, |
| 226 | // Variable length bytes |
| 227 | Self::BU8(_) => Kind::BU8, |
| 228 | Self::BU16(_) => Kind::BU16, |
| 229 | Self::BU32(_) => Kind::BU32, |
| 230 | Self::BU64(_) => Kind::BU64, |
| 231 | Self::BC64(_) => Kind::BC64, |
| 232 | // Fixed length bytes |
| 233 | Self::B2(_) => Kind::B2, |
| 234 | Self::B3(_) => Kind::B3, |
| 235 | Self::B4(_) => Kind::B4, |
| 236 | Self::B5(_) => Kind::B5, |
| 237 | Self::B6(_) => Kind::B6, |
| 238 | Self::B7(_) => Kind::B7, |
| 239 | Self::B8(_) => Kind::B8, |
| 240 | Self::B9(_) => Kind::B9, |
| 241 | Self::B10(_) => Kind::B10, |
| 242 | Self::B16(_) => Kind::B16, |
| 243 | Self::B32(_) => Kind::B32, |
| 244 | |
| 245 | // Fixed length numbers |
| 246 | Self::Tup2u8(_) => Kind::Tup2u8, |
| 247 | Self::Tup3u8(_) => Kind::Tup3u8, |
| 248 | Self::Tup4u8(_) => Kind::Tup4u8, |
| 249 | Self::Tup5u8(_) => Kind::Tup5u8, |
| 250 | Self::Tup6u8(_) => Kind::Tup6u8, |
| 251 | Self::Tup7u8(_) => Kind::Tup7u8, |
| 252 | Self::Tup8u8(_) => Kind::Tup8u8, |
| 253 | Self::Tup9u8(_) => Kind::Tup9u8, |
| 254 | Self::Tup10u8(_) => Kind::Tup10u8, |
| 255 | |
| 256 | Self::Tup2u16(_) => Kind::Tup2u16, |
| 257 | Self::Tup3u16(_) => Kind::Tup3u16, |
| 258 | Self::Tup4u16(_) => Kind::Tup4u16, |
| 259 | Self::Tup5u16(_) => Kind::Tup5u16, |
| 260 | Self::Tup6u16(_) => Kind::Tup6u16, |
| 261 | Self::Tup7u16(_) => Kind::Tup7u16, |
| 262 | Self::Tup8u16(_) => Kind::Tup8u16, |
| 263 | Self::Tup9u16(_) => Kind::Tup9u16, |
| 264 | Self::Tup10u16(_) => Kind::Tup10u16, |
| 265 | |
| 266 | Self::Tup2u32(_) => Kind::Tup2u32, |
| 267 | Self::Tup3u32(_) => Kind::Tup3u32, |
| 268 | Self::Tup4u32(_) => Kind::Tup4u32, |
| 269 | Self::Tup5u32(_) => Kind::Tup5u32, |
| 270 | Self::Tup6u32(_) => Kind::Tup6u32, |
| 271 | Self::Tup7u32(_) => Kind::Tup7u32, |
| 272 | Self::Tup8u32(_) => Kind::Tup8u32, |
| 273 | Self::Tup9u32(_) => Kind::Tup9u32, |
| 274 | Self::Tup10u32(_) => Kind::Tup10u32, |
| 275 | |
| 276 | Self::Tup2u64(_) => Kind::Tup2u64, |
| 277 | Self::Tup3u64(_) => Kind::Tup3u64, |
| 278 | Self::Tup4u64(_) => Kind::Tup4u64, |
| 279 | Self::Tup5u64(_) => Kind::Tup5u64, |
| 280 | Self::Tup6u64(_) => Kind::Tup6u64, |
| 281 | Self::Tup7u64(_) => Kind::Tup7u64, |
| 282 | Self::Tup8u64(_) => Kind::Tup8u64, |
| 283 | Self::Tup9u64(_) => Kind::Tup9u64, |
| 284 | Self::Tup10u64(_) => Kind::Tup10u64, |
| 285 | |
| 286 | Self::Tup2i8(_) => Kind::Tup2i8, |
| 287 | Self::Tup3i8(_) => Kind::Tup3i8, |
| 288 | Self::Tup4i8(_) => Kind::Tup4i8, |
| 289 | Self::Tup5i8(_) => Kind::Tup5i8, |
| 290 | Self::Tup6i8(_) => Kind::Tup6i8, |
| 291 | Self::Tup7i8(_) => Kind::Tup7i8, |
| 292 | Self::Tup8i8(_) => Kind::Tup8i8, |
| 293 | Self::Tup9i8(_) => Kind::Tup9i8, |
| 294 | Self::Tup10i8(_) => Kind::Tup10i8, |
| 295 | |
| 296 | Self::Tup2i16(_) => Kind::Tup2i16, |
| 297 | Self::Tup3i16(_) => Kind::Tup3i16, |
| 298 | Self::Tup4i16(_) => Kind::Tup4i16, |
| 299 | Self::Tup5i16(_) => Kind::Tup5i16, |
| 300 | Self::Tup6i16(_) => Kind::Tup6i16, |
| 301 | Self::Tup7i16(_) => Kind::Tup7i16, |
| 302 | Self::Tup8i16(_) => Kind::Tup8i16, |
| 303 | Self::Tup9i16(_) => Kind::Tup9i16, |
| 304 | Self::Tup10i16(_) => Kind::Tup10i16, |
| 305 | |
| 306 | Self::Tup2i32(_) => Kind::Tup2i32, |
| 307 | Self::Tup3i32(_) => Kind::Tup3i32, |
| 308 | Self::Tup4i32(_) => Kind::Tup4i32, |
| 309 | Self::Tup5i32(_) => Kind::Tup5i32, |
| 310 | Self::Tup6i32(_) => Kind::Tup6i32, |
| 311 | Self::Tup7i32(_) => Kind::Tup7i32, |
| 312 | Self::Tup8i32(_) => Kind::Tup8i32, |
| 313 | Self::Tup9i32(_) => Kind::Tup9i32, |
| 314 | Self::Tup10i32(_) => Kind::Tup10i32, |
| 315 | |
| 316 | Self::Tup2i64(_) => Kind::Tup2i64, |
| 317 | Self::Tup3i64(_) => Kind::Tup3i64, |
| 318 | Self::Tup4i64(_) => Kind::Tup4i64, |
| 319 | Self::Tup5i64(_) => Kind::Tup5i64, |
| 320 | Self::Tup6i64(_) => Kind::Tup6i64, |
| 321 | Self::Tup7i64(_) => Kind::Tup7i64, |
| 322 | Self::Tup8i64(_) => Kind::Tup8i64, |
| 323 | Self::Tup9i64(_) => Kind::Tup9i64, |
| 324 | Self::Tup10i64(_) => Kind::Tup10i64, |
| 325 | |
| 326 | //// Scheduled for removal |
| 327 | //Self::PartKey(_) => Kind::PartKey, |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | } |
| 332 | |
| 333 | #[derive(Debug, Eq, PartialEq, Copy, Clone)] |
| 334 | pub enum KindCase { |
| 335 | None, |
| 336 | AtomLogic, |
| 337 | AtomFixed, |
| 338 | AtomVariable, |
| 339 | MoleculeUnitary, |
| 340 | MoleculeMixed, |
| 341 | MoleculeSame, |
| 342 | } |
| 343 | |
| 344 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 345 | pub enum KindClass { |
| 346 | None, |
| 347 | Atomic, |
| 348 | Molecular, |
| 349 | } |
| 350 | |
| 351 | impl KindCase { |
| 352 | pub fn class(&self) -> KindClass { |
| 353 | match self { |
| 354 | Self::None => KindClass::None, |
| 355 | Self::MoleculeUnitary | |
| 356 | Self::MoleculeMixed | |
| 357 | Self::MoleculeSame => KindClass::Molecular, |
| 358 | _ => KindClass::Atomic, |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | pub fn accepts_strings(&self) -> bool { |
| 363 | match self { |
| 364 | Self::MoleculeUnitary | Self::MoleculeMixed => true, |
| 365 | _ => false, |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | impl Kind { |
| 371 | |
| 372 | /// Primary classification of `Kind`s. |
| 373 | pub fn case(&self) -> KindCase { |
| 374 | match *self { |
| 375 | Self::Empty | |
| 376 | Self::True | |
| 377 | Self::False | |
| 378 | Self::None => KindCase::AtomLogic, |
| 379 | Self::U8 | |
| 380 | Self::U16 | |
| 381 | Self::U32 | |
| 382 | Self::U64 | |
| 383 | Self::U128 | |
| 384 | Self::I8 | |
| 385 | Self::I16 | |
| 386 | Self::I32 | |
| 387 | Self::I64 | |
| 388 | Self::I128 | |
| 389 | Self::F32 | |
| 390 | Self::F64 => KindCase::AtomFixed, |
| 391 | Self::Aint | |
| 392 | Self::Adec | |
| 393 | Self::C64 | |
| 394 | Self::Str => KindCase::AtomVariable, |
| 395 | Self::Usr(_) | |
| 396 | Self::Box(_) | |
| 397 | Self::Some(_) | |
| 398 | Self::ABox(_) => KindCase::MoleculeUnitary, |
| 399 | Self::List | |
| 400 | Self::Tup2 | |
| 401 | Self::Tup3 | |
| 402 | Self::Tup4 | |
| 403 | Self::Tup5 | |
| 404 | Self::Tup6 | |
| 405 | Self::Tup7 | |
| 406 | Self::Tup8 | |
| 407 | Self::Tup9 | |
| 408 | Self::Tup10 | |
| 409 | Self::Map | |
| 410 | Self::OrdMap => KindCase::MoleculeMixed, |
| 411 | Self::BU8 | |
| 412 | Self::BU16 | |
| 413 | Self::BU32 | |
| 414 | Self::BU64 | |
| 415 | Self::BC64 | |
| 416 | Self::B32 | |
| 417 | Self::Tup5u64 => KindCase::MoleculeSame, |
| 418 | _ => KindCase::None, |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | pub fn is_dataless(&self) -> bool { |
| 423 | if self.case() == KindCase::AtomLogic { |
| 424 | return true; |
| 425 | } |
| 426 | match self { |
| 427 | Self::Usr(ukid) if ukid.kind().is_none() => true, |
| 428 | _ => false, |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | pub fn is_abox(&self) -> bool { |
| 433 | match self { |
| 434 | Self::ABox(_) => true, |
| 435 | _ => false, |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | pub fn is_usr(&self) -> bool { |
| 440 | match self { |
| 441 | Self::Usr(_ukid) => true, |
| 442 | _ => false, |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | pub fn is_map(&self) -> bool { |
| 447 | match self { |
| 448 | Self::Map | Self::OrdMap => true, |
| 449 | _ => false, |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | pub fn usr( |
| 454 | &self, |
| 455 | code: u16, |
| 456 | lab_opt: Option<&str>, |
| 457 | ) |
| 458 | -> Self |
| 459 | { |
| 460 | Self::Usr(UsrKindId::new(code, lab_opt, Some(self.clone()))) |
| 461 | } |
| 462 | |
| 463 | /// Human description of kinds. |
| 464 | pub fn desc(&self) -> &'static str { |
| 465 | match *self { |
| 466 | // "Which represents..." |
| 467 | Self::Unknown => "A daticle of unknown kind", |
| 468 | // Atomic Kinds =========================== |
| 469 | // Logic |
| 470 | Self::Empty => "A daticle that is empty", |
| 471 | Self::True => "A true boolean value", |
| 472 | Self::False => "A false boolean value", |
| 473 | Self::None => "The absence of an optional value", |
| 474 | // Fixed |
| 475 | Self::U8 => "An unsigned 8 bit integer", |
| 476 | Self::U16 => "An unsigned 16 bit integer", |
| 477 | Self::U32 => "An unsigned 32 bit integer", |
| 478 | Self::U64 => "An unsigned 64 bit integer", |
| 479 | Self::U128 => "An unsigned 128 bit integer", |
| 480 | Self::I8 => "A signed 8 bit integer", |
| 481 | Self::I16 => "A signed 16 bit integer", |
| 482 | Self::I32 => "A signed 32 bit integer", |
| 483 | Self::I64 => "A signed 64 bit integer", |
| 484 | Self::I128 => "A signed 128 bit integer", |
| 485 | Self::F32 => "A 32 bit floating point number", |
| 486 | Self::F64 => "A 64 bit floating point number", |
| 487 | // Variable |
| 488 | Self::Aint => "An integer of arbitrary size", |
| 489 | Self::Adec => "A decimal number of arbitary size and precision", |
| 490 | Self::C64 => "A binary-compressed u64", |
| 491 | Self::Str => "A character string", |
| 492 | // Molecular Kinds ======================== |
| 493 | // Unitary |
| 494 | Self::Usr(_) => "A user defined kind with an optionally nested daticle", |
| 495 | Self::Box(_) => "A nested daticle", |
| 496 | Self::Some(_) => "An optional daticle containing a nested daticle", |
| 497 | Self::ABox(_) => "A nested daticle including textual annotation", |
| 498 | // Heterogenous |
| 499 | Self::List => "A heterogenous list of daticles", |
| 500 | Self::Tup2 => "A heterogenous tuple of two daticles", |
| 501 | Self::Tup3 => "A heterogenous tuple of three daticles", |
| 502 | Self::Tup4 => "A heterogenous tuple of four daticles", |
| 503 | Self::Tup5 => "A heterogenous tuple of five daticles", |
| 504 | Self::Tup6 => "A heterogenous tuple of six daticles", |
| 505 | Self::Tup7 => "A heterogenous tuple of seven daticles", |
| 506 | Self::Tup8 => "A heterogenous tuple of eight daticles", |
| 507 | Self::Tup9 => "A heterogenous tuple of nine daticles", |
| 508 | Self::Tup10 => "A heterogenous tuple of ten daticles", |
| 509 | Self::Map => "A heterogenous map of daticles", |
| 510 | Self::OrdMap => "A heterogenous ordered map of daticles", |
| 511 | // Homogenous |
| 512 | Self::Vek => "An homogenous vector of daticles", |
| 513 | // Variable length bytes |
| 514 | Self::BU8 => "A vector of u8 bytes with length encoded as a u8", |
| 515 | Self::BU16 => "A vector of u8 bytes with length encoded as a u16", |
| 516 | Self::BU32 => "A vector of u8 bytes with length encoded as a u32", |
| 517 | Self::BU64 => "A vector of u8 bytes with length encoded as a u64", |
| 518 | Self::BC64 => "A vector of u8 bytes with length encoded as a binary-compressed u64", |
| 519 | // Fixed length bytes |
| 520 | Self::B2 => "A tuple of two u8 bytes", |
| 521 | Self::B3 => "A tuple of three u8 bytes", |
| 522 | Self::B4 => "A tuple of four u8 bytes", |
| 523 | Self::B5 => "A tuple of five u8 bytes", |
| 524 | Self::B6 => "A tuple of six u8 bytes", |
| 525 | Self::B7 => "A tuple of seven u8 bytes", |
| 526 | Self::B8 => "A tuple of eight u8 bytes", |
| 527 | Self::B9 => "A tuple of nine u8 bytes", |
| 528 | Self::B10 => "A tuple of ten u8 bytes", |
| 529 | Self::B16 => "A tuple of sixteen u8 bytes", |
| 530 | Self::B32 => "A tuple of thirty-two u8 bytes", |
| 531 | // Variable length numbers |
| 532 | Self::Vu16 => "A vector of u16 values, not yet implemented", |
| 533 | Self::Vu32 => "A vector of u32 values, not yet implemented", |
| 534 | Self::Vu64 => "A vector of u64 values, not yet implemented", |
| 535 | Self::Vu128 => "A vector of u128 values, not yet implemented", |
| 536 | Self::Vi8 => "A vector of i8 values, not yet implemented", |
| 537 | Self::Vi16 => "A vector of i16 values, not yet implemented", |
| 538 | Self::Vi32 => "A vector of i32 values, not yet implemented", |
| 539 | Self::Vi64 => "A vector of i64 values, not yet implemented", |
| 540 | Self::Vi128 => "A vector of i128 values, not yet implemented", |
| 541 | // Fixed length numbers |
| 542 | Self::Tup2u16 => "A tuple of two u16 values", |
| 543 | Self::Tup3u16 => "A tuple of three u16 values", |
| 544 | Self::Tup4u16 => "A tuple of four u16 values", |
| 545 | Self::Tup5u16 => "A tuple of five u16 values" , |
| 546 | Self::Tup6u16 => "A tuple of six u16 values", |
| 547 | Self::Tup7u16 => "A tuple of seven u16 values", |
| 548 | Self::Tup8u16 => "A tuple of eight u16 values", |
| 549 | Self::Tup9u16 => "A tuple of nine u16 values", |
| 550 | Self::Tup10u16 => "A tuple of ten u16 values", |
| 551 | |
| 552 | Self::Tup2u32 => "A tuple of two u32 values", |
| 553 | Self::Tup3u32 => "A tuple of three u32 values", |
| 554 | Self::Tup4u32 => "A tuple of four u32 values", |
| 555 | Self::Tup5u32 => "A tuple of five u32 values" , |
| 556 | Self::Tup6u32 => "A tuple of six u32 values", |
| 557 | Self::Tup7u32 => "A tuple of seven u32 values", |
| 558 | Self::Tup8u32 => "A tuple of eight u32 values", |
| 559 | Self::Tup9u32 => "A tuple of nine u32 values", |
| 560 | Self::Tup10u32 => "A tuple of ten u32 values", |
| 561 | |
| 562 | Self::Tup2u64 => "A tuple of two u64 values", |
| 563 | Self::Tup3u64 => "A tuple of three u64 values", |
| 564 | Self::Tup4u64 => "A tuple of four u64 values", |
| 565 | Self::Tup5u64 => "A tuple of five u64 values" , |
| 566 | Self::Tup6u64 => "A tuple of six u64 values", |
| 567 | Self::Tup7u64 => "A tuple of seven u64 values", |
| 568 | Self::Tup8u64 => "A tuple of eight u64 values", |
| 569 | Self::Tup9u64 => "A tuple of nine u64 values", |
| 570 | Self::Tup10u64 => "A tuple of ten u64 values", |
| 571 | |
| 572 | Self::Tup2u8 => "A tuple of two u8 values", |
| 573 | Self::Tup3u8 => "A tuple of three u8 values", |
| 574 | Self::Tup4u8 => "A tuple of four u8 values", |
| 575 | Self::Tup5u8 => "A tuple of five u8 values", |
| 576 | Self::Tup6u8 => "A tuple of six u8 values", |
| 577 | Self::Tup7u8 => "A tuple of seven u8 values", |
| 578 | Self::Tup8u8 => "A tuple of eight u8 values", |
| 579 | Self::Tup9u8 => "A tuple of nine u8 values", |
| 580 | Self::Tup10u8 => "A tuple of ten u8 values", |
| 581 | |
| 582 | Self::Tup2i8 => "A tuple of two i8 values, not yet implemented", |
| 583 | Self::Tup3i8 => "A tuple of three i8 values, not yet implemented", |
| 584 | Self::Tup4i8 => "A tuple of four i8 values, not yet implemented", |
| 585 | Self::Tup5i8 => "A tuple of five i8 values, not yet implemented" , |
| 586 | Self::Tup6i8 => "A tuple of six i8 values, not yet implemented", |
| 587 | Self::Tup7i8 => "A tuple of seven i8 values, not yet implemented", |
| 588 | Self::Tup8i8 => "A tuple of eight i8 values, not yet implemented", |
| 589 | Self::Tup9i8 => "A tuple of nine i8 values, not yet implemented", |
| 590 | Self::Tup10i8 => "A tuple of ten i8 values, not yet implemented", |
| 591 | |
| 592 | Self::Tup2i16 => "A tuple of two i16 values, not yet implemented", |
| 593 | Self::Tup3i16 => "A tuple of three i16 values, not yet implemented", |
| 594 | Self::Tup4i16 => "A tuple of four i16 values, not yet implemented", |
| 595 | Self::Tup5i16 => "A tuple of five i16 values, not yet implemented" , |
| 596 | Self::Tup6i16 => "A tuple of six i16 values, not yet implemented", |
| 597 | Self::Tup7i16 => "A tuple of seven i16 values, not yet implemented", |
| 598 | Self::Tup8i16 => "A tuple of eight i16 values, not yet implemented", |
| 599 | Self::Tup9i16 => "A tuple of nine i16 values, not yet implemented", |
| 600 | Self::Tup10i16 => "A tuple of ten i16 values, not yet implemented", |
| 601 | |
| 602 | Self::Tup2i32 => "A tuple of two i32 values, not yet implemented", |
| 603 | Self::Tup3i32 => "A tuple of three i32 values, not yet implemented", |
| 604 | Self::Tup4i32 => "A tuple of four i32 values, not yet implemented", |
| 605 | Self::Tup5i32 => "A tuple of five i32 values, not yet implemented" , |
| 606 | Self::Tup6i32 => "A tuple of six i32 values, not yet implemented", |
| 607 | Self::Tup7i32 => "A tuple of seven i32 values, not yet implemented", |
| 608 | Self::Tup8i32 => "A tuple of eight i32 values, not yet implemented", |
| 609 | Self::Tup9i32 => "A tuple of nine i32 values, not yet implemented", |
| 610 | Self::Tup10i32 => "A tuple of ten i32 values, not yet implemented", |
| 611 | |
| 612 | Self::Tup2i64 => "A tuple of two i64 values, not yet implemented", |
| 613 | Self::Tup3i64 => "A tuple of three i64 values, not yet implemented", |
| 614 | Self::Tup4i64 => "A tuple of four i64 values, not yet implemented", |
| 615 | Self::Tup5i64 => "A tuple of five i64 values, not yet implemented" , |
| 616 | Self::Tup6i64 => "A tuple of six i64 values, not yet implemented", |
| 617 | Self::Tup7i64 => "A tuple of seven i64 values, not yet implemented", |
| 618 | Self::Tup8i64 => "A tuple of eight i64 values, not yet implemented", |
| 619 | Self::Tup9i64 => "A tuple of nine i64 values, not yet implemented", |
| 620 | Self::Tup10i64 => "A tuple of ten i64 values, not yet implemented", |
| 621 | |
| 622 | //// Scheduled for removal |
| 623 | //PartKey, |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | pub fn is_option(&self) -> bool { |
| 628 | match self { |
| 629 | Self::None | Self::Some(_) => true, |
| 630 | _ => false, |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | pub fn equals(&self, other: &Kind) -> bool { |
| 635 | if self.is_option() && other.is_option() { |
| 636 | true |
| 637 | } else { |
| 638 | self == other |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | impl Dat { |
| 644 | |
| 645 | /// Used mainly for error reporting during byte decoding. |
| 646 | pub fn code_name(code: u8) -> String { |
| 647 | fmt!("{:?}", match code { |
| 648 | // Atomic Kinds =========================== |
| 649 | // Logic |
| 650 | Self::EMPTY_CODE => Kind::Empty, |
| 651 | Self::TRUE_CODE => Kind::True, |
| 652 | Self::FALSE_CODE => Kind::False, |
| 653 | Self::OPT_NONE_CODE => Kind::None, |
| 654 | // Fixed |
| 655 | Self::U8_CODE => Kind::U8, |
| 656 | Self::U16_CODE => Kind::U16, |
| 657 | Self::U32_CODE => Kind::U32, |
| 658 | Self::U64_CODE => Kind::U64, |
| 659 | Self::U128_CODE => Kind::U128, |
| 660 | Self::I8_CODE => Kind::I8, |
| 661 | Self::I16_CODE => Kind::I16, |
| 662 | Self::I32_CODE => Kind::I32, |
| 663 | Self::I64_CODE => Kind::I64, |
| 664 | Self::I128_CODE => Kind::I128, |
| 665 | Self::F32_CODE => Kind::F32, |
| 666 | Self::F64_CODE => Kind::F64, |
| 667 | // Variable |
| 668 | Self::AINT_CODE => Kind::Aint, |
| 669 | Self::ADEC_CODE => Kind::Adec, |
| 670 | Self::C64_CODE_START..=Dat::C64_CODE_END => Kind::C64, |
| 671 | Self::STR_CODE => Kind::Str, |
| 672 | // Molecule Kinds ========================= |
| 673 | // Unitary |
| 674 | Self::USR_CODE => Kind::Usr(UsrKindId::new(0, None, None)), |
| 675 | Self::BOX_CODE => Kind::Box(None), |
| 676 | Self::OPT_SOME_CODE => Kind::Some(None), |
| 677 | // Heterogenous |
| 678 | Self::LIST_CODE => Kind::List, |
| 679 | Self::TUP2_CODE => Kind::Tup2, |
| 680 | Self::TUP3_CODE => Kind::Tup3, |
| 681 | Self::TUP4_CODE => Kind::Tup4, |
| 682 | Self::TUP5_CODE => Kind::Tup5, |
| 683 | Self::TUP6_CODE => Kind::Tup6, |
| 684 | Self::TUP7_CODE => Kind::Tup7, |
| 685 | Self::TUP8_CODE => Kind::Tup8, |
| 686 | Self::TUP9_CODE => Kind::Tup9, |
| 687 | Self::TUP10_CODE => Kind::Tup10, |
| 688 | Self::MAP_CODE => Kind::Map, |
| 689 | Self::OMAP_CODE => Kind::OrdMap, |
| 690 | // Homogenous |
| 691 | Self::VEK_CODE => Kind::Vek, |
| 692 | // Variable length bytes |
| 693 | Self::BU8_CODE => Kind::BU8, |
| 694 | Self::BU16_CODE => Kind::BU16, |
| 695 | Self::BU32_CODE => Kind::BU32, |
| 696 | Self::BU64_CODE => Kind::BU64, |
| 697 | Self::BC64_CODE => Kind::BC64, |
| 698 | // Fixed length bytes |
| 699 | Self::B2_CODE => Kind::B2, |
| 700 | Self::B3_CODE => Kind::B3, |
| 701 | Self::B4_CODE => Kind::B4, |
| 702 | Self::B5_CODE => Kind::B5, |
| 703 | Self::B6_CODE => Kind::B6, |
| 704 | Self::B7_CODE => Kind::B7, |
| 705 | Self::B8_CODE => Kind::B8, |
| 706 | Self::B9_CODE => Kind::B9, |
| 707 | Self::B10_CODE => Kind::B10, |
| 708 | Self::B16_CODE => Kind::B16, |
| 709 | Self::B32_CODE => Kind::B32, |
| 710 | // Fixed length numbers |
| 711 | Self::TUP2_U16_CODE => Kind::Tup2u16, |
| 712 | Self::TUP3_U16_CODE => Kind::Tup3u16, |
| 713 | Self::TUP4_U16_CODE => Kind::Tup4u16, |
| 714 | Self::TUP5_U16_CODE => Kind::Tup5u16, |
| 715 | Self::TUP6_U16_CODE => Kind::Tup6u16, |
| 716 | Self::TUP7_U16_CODE => Kind::Tup7u16, |
| 717 | Self::TUP8_U16_CODE => Kind::Tup8u16, |
| 718 | Self::TUP9_U16_CODE => Kind::Tup9u16, |
| 719 | Self::TUP10_U16_CODE => Kind::Tup10u16, |
| 720 | |
| 721 | Self::TUP2_U32_CODE => Kind::Tup2u32, |
| 722 | Self::TUP3_U32_CODE => Kind::Tup3u32, |
| 723 | Self::TUP4_U32_CODE => Kind::Tup4u32, |
| 724 | Self::TUP5_U32_CODE => Kind::Tup5u32, |
| 725 | Self::TUP6_U32_CODE => Kind::Tup6u32, |
| 726 | Self::TUP7_U32_CODE => Kind::Tup7u32, |
| 727 | Self::TUP8_U32_CODE => Kind::Tup8u32, |
| 728 | Self::TUP9_U32_CODE => Kind::Tup9u32, |
| 729 | Self::TUP10_U32_CODE => Kind::Tup10u32, |
| 730 | |
| 731 | Self::TUP2_U64_CODE => Kind::Tup2u64, |
| 732 | Self::TUP3_U64_CODE => Kind::Tup3u64, |
| 733 | Self::TUP4_U64_CODE => Kind::Tup4u64, |
| 734 | Self::TUP5_U64_CODE => Kind::Tup5u64, |
| 735 | Self::TUP6_U64_CODE => Kind::Tup6u64, |
| 736 | Self::TUP7_U64_CODE => Kind::Tup7u64, |
| 737 | Self::TUP8_U64_CODE => Kind::Tup8u64, |
| 738 | Self::TUP9_U64_CODE => Kind::Tup9u64, |
| 739 | Self::TUP10_U64_CODE => Kind::Tup10u64, |
| 740 | |
| 741 | //// Scheduled for removal |
| 742 | //Self::PARTKEY_CODE => fmt!("Dat::PartKey"), |
| 743 | |
| 744 | _ => Kind::Unknown, |
| 745 | }) |
| 746 | } |
| 747 | |
| 748 | #[allow(dead_code)] |
| 749 | pub fn to_code(&self) -> u8 { |
| 750 | match self { |
| 751 | // Atomic Kinds =========================== |
| 752 | // Logic |
| 753 | Self::Empty => Self::EMPTY_CODE, |
| 754 | Self::Bool(b) => if *b { Self::TRUE_CODE } else { Self::FALSE_CODE }, |
| 755 | // Fixed |
| 756 | Self::U8(_) => Self::U8_CODE, |
| 757 | Self::U16(_) => Self::U16_CODE, |
| 758 | Self::U32(_) => Self::U32_CODE, |
| 759 | Self::U64(_) => Self::U64_CODE, |
| 760 | Self::U128(_) => Self::U128_CODE, |
| 761 | Self::I8(_) => Self::I8_CODE, |
| 762 | Self::I16(_) => Self::I16_CODE, |
| 763 | Self::I32(_) => Self::I32_CODE, |
| 764 | Self::I64(_) => Self::I64_CODE, |
| 765 | Self::I128(_) => Self::I128_CODE, |
| 766 | Self::F32(_) => Self::F32_CODE, |
| 767 | Self::F64(_) => Self::F64_CODE, |
| 768 | // Variable |
| 769 | Self::Aint(_) => Self::AINT_CODE, |
| 770 | Self::Adec(_) => Self::ADEC_CODE, |
| 771 | Self::C64(_) => Self::C64_CODE_START, // baseline value, c64 = 0 |
| 772 | // C64_CODE_START+1: 0 < c64 <= 255 |
| 773 | // C64_CODE_START+2: 255 < c64 <= 65535 |
| 774 | // C64_CODE_START+3: 65535 < c64 <= 16777215 |
| 775 | // C64_CODE_START+4: 16777215 < c64 <= 4294967295 |
| 776 | // C64_CODE_START+5: 4294967295 < c64 <= 1099511627775 |
| 777 | // C64_CODE_START+6: 1099511627775 < c64 <= 281474976710655 |
| 778 | // C64_CODE_START+7: 281474976710655 < c64 <= 72057594037927935 |
| 779 | // C64_CODE_START+8: 72057594037927935 < c64 <= 18446744073709551615 |
| 780 | Self::Str(_) => Self::STR_CODE, |
| 781 | // Molecular Kinds ======================== |
| 782 | // Unitary |
| 783 | Self::Usr(_, _) => Self::USR_CODE, |
| 784 | Self::Box(_) => Self::BOX_CODE, |
| 785 | Self::Opt(boxoptd) => match **boxoptd { |
| 786 | None => Self::OPT_NONE_CODE, |
| 787 | Some(_) => Self::OPT_SOME_CODE, |
| 788 | }, |
| 789 | Self::ABox(_, _, _) => Self::ABOX_CODE, |
| 790 | // Heterogenous |
| 791 | Self::List(_) => Self::LIST_CODE, |
| 792 | Self::Tup2(_) => Self::TUP2_CODE, |
| 793 | Self::Tup3(_) => Self::TUP3_CODE, |
| 794 | Self::Tup4(_) => Self::TUP4_CODE, |
| 795 | Self::Tup5(_) => Self::TUP5_CODE, |
| 796 | Self::Tup6(_) => Self::TUP6_CODE, |
| 797 | Self::Tup7(_) => Self::TUP7_CODE, |
| 798 | Self::Tup8(_) => Self::TUP8_CODE, |
| 799 | Self::Tup9(_) => Self::TUP9_CODE, |
| 800 | Self::Tup10(_) => Self::TUP10_CODE, |
| 801 | Self::Map(_) => Self::MAP_CODE, |
| 802 | Self::OrdMap(_) => Self::OMAP_CODE, |
| 803 | // Homogenous |
| 804 | Self::Vek(_) => Self::VEK_CODE, |
| 805 | // Variable length bytes |
| 806 | Self::BU8(_) => Self::BU8_CODE, |
| 807 | Self::BU16(_) => Self::BU16_CODE, |
| 808 | Self::BU32(_) => Self::BU32_CODE, |
| 809 | Self::BU64(_) => Self::BU64_CODE, |
| 810 | Self::BC64(_) => Self::BC64_CODE, |
| 811 | // Fixed length bytes |
| 812 | Self::B2(_) => Self::B2_CODE, |
| 813 | Self::B3(_) => Self::B3_CODE, |
| 814 | Self::B4(_) => Self::B4_CODE, |
| 815 | Self::B5(_) => Self::B5_CODE, |
| 816 | Self::B6(_) => Self::B6_CODE, |
| 817 | Self::B7(_) => Self::B7_CODE, |
| 818 | Self::B8(_) => Self::B8_CODE, |
| 819 | Self::B9(_) => Self::B9_CODE, |
| 820 | Self::B10(_) => Self::B10_CODE, |
| 821 | Self::B16(_) => Self::B16_CODE, |
| 822 | Self::B32(_) => Self::B32_CODE, |
| 823 | // Fixed length numbers |
| 824 | Self::Tup2u16(_) => Self::TUP2_U16_CODE, |
| 825 | Self::Tup3u16(_) => Self::TUP3_U16_CODE, |
| 826 | Self::Tup4u16(_) => Self::TUP4_U16_CODE, |
| 827 | Self::Tup5u16(_) => Self::TUP5_U16_CODE, |
| 828 | Self::Tup6u16(_) => Self::TUP6_U16_CODE, |
| 829 | Self::Tup7u16(_) => Self::TUP7_U16_CODE, |
| 830 | Self::Tup8u16(_) => Self::TUP8_U16_CODE, |
| 831 | Self::Tup9u16(_) => Self::TUP9_U16_CODE, |
| 832 | Self::Tup10u16(_) => Self::TUP10_U16_CODE, |
| 833 | |
| 834 | Self::Tup2u32(_) => Self::TUP2_U32_CODE, |
| 835 | Self::Tup3u32(_) => Self::TUP3_U32_CODE, |
| 836 | Self::Tup4u32(_) => Self::TUP4_U32_CODE, |
| 837 | Self::Tup5u32(_) => Self::TUP5_U32_CODE, |
| 838 | Self::Tup6u32(_) => Self::TUP6_U32_CODE, |
| 839 | Self::Tup7u32(_) => Self::TUP7_U32_CODE, |
| 840 | Self::Tup8u32(_) => Self::TUP8_U32_CODE, |
| 841 | Self::Tup9u32(_) => Self::TUP9_U32_CODE, |
| 842 | Self::Tup10u32(_) => Self::TUP10_U32_CODE, |
| 843 | |
| 844 | Self::Tup2u64(_) => Self::TUP2_U64_CODE, |
| 845 | Self::Tup3u64(_) => Self::TUP3_U64_CODE, |
| 846 | Self::Tup4u64(_) => Self::TUP4_U64_CODE, |
| 847 | Self::Tup5u64(_) => Self::TUP5_U64_CODE, |
| 848 | Self::Tup6u64(_) => Self::TUP6_U64_CODE, |
| 849 | Self::Tup7u64(_) => Self::TUP7_U64_CODE, |
| 850 | Self::Tup8u64(_) => Self::TUP8_U64_CODE, |
| 851 | Self::Tup9u64(_) => Self::TUP9_U64_CODE, |
| 852 | Self::Tup10u64(_) => Self::TUP10_U64_CODE, |
| 853 | |
| 854 | Self::Tup2u8(_) => Self::TUP2_U8_CODE, |
| 855 | Self::Tup3u8(_) => Self::TUP3_U8_CODE, |
| 856 | Self::Tup4u8(_) => Self::TUP4_U8_CODE, |
| 857 | Self::Tup5u8(_) => Self::TUP5_U8_CODE, |
| 858 | Self::Tup6u8(_) => Self::TUP6_U8_CODE, |
| 859 | Self::Tup7u8(_) => Self::TUP7_U8_CODE, |
| 860 | Self::Tup8u8(_) => Self::TUP8_U8_CODE, |
| 861 | Self::Tup9u8(_) => Self::TUP9_U8_CODE, |
| 862 | Self::Tup10u8(_) => Self::TUP10_U8_CODE, |
| 863 | |
| 864 | Self::Tup2i8(_) => Self::TUP2_I8_CODE, |
| 865 | Self::Tup3i8(_) => Self::TUP3_I8_CODE, |
| 866 | Self::Tup4i8(_) => Self::TUP4_I8_CODE, |
| 867 | Self::Tup5i8(_) => Self::TUP5_I8_CODE, |
| 868 | Self::Tup6i8(_) => Self::TUP6_I8_CODE, |
| 869 | Self::Tup7i8(_) => Self::TUP7_I8_CODE, |
| 870 | Self::Tup8i8(_) => Self::TUP8_I8_CODE, |
| 871 | Self::Tup9i8(_) => Self::TUP9_I8_CODE, |
| 872 | Self::Tup10i8(_) => Self::TUP10_I8_CODE, |
| 873 | |
| 874 | Self::Tup2i16(_) => Self::TUP2_I16_CODE, |
| 875 | Self::Tup3i16(_) => Self::TUP3_I16_CODE, |
| 876 | Self::Tup4i16(_) => Self::TUP4_I16_CODE, |
| 877 | Self::Tup5i16(_) => Self::TUP5_I16_CODE, |
| 878 | Self::Tup6i16(_) => Self::TUP6_I16_CODE, |
| 879 | Self::Tup7i16(_) => Self::TUP7_I16_CODE, |
| 880 | Self::Tup8i16(_) => Self::TUP8_I16_CODE, |
| 881 | Self::Tup9i16(_) => Self::TUP9_I16_CODE, |
| 882 | Self::Tup10i16(_) => Self::TUP10_I16_CODE, |
| 883 | |
| 884 | Self::Tup2i32(_) => Self::TUP2_I32_CODE, |
| 885 | Self::Tup3i32(_) => Self::TUP3_I32_CODE, |
| 886 | Self::Tup4i32(_) => Self::TUP4_I32_CODE, |
| 887 | Self::Tup5i32(_) => Self::TUP5_I32_CODE, |
| 888 | Self::Tup6i32(_) => Self::TUP6_I32_CODE, |
| 889 | Self::Tup7i32(_) => Self::TUP7_I32_CODE, |
| 890 | Self::Tup8i32(_) => Self::TUP8_I32_CODE, |
| 891 | Self::Tup9i32(_) => Self::TUP9_I32_CODE, |
| 892 | Self::Tup10i32(_) => Self::TUP10_I32_CODE, |
| 893 | |
| 894 | Self::Tup2i64(_) => Self::TUP2_I64_CODE, |
| 895 | Self::Tup3i64(_) => Self::TUP3_I64_CODE, |
| 896 | Self::Tup4i64(_) => Self::TUP4_I64_CODE, |
| 897 | Self::Tup5i64(_) => Self::TUP5_I64_CODE, |
| 898 | Self::Tup6i64(_) => Self::TUP6_I64_CODE, |
| 899 | Self::Tup7i64(_) => Self::TUP7_I64_CODE, |
| 900 | Self::Tup8i64(_) => Self::TUP8_I64_CODE, |
| 901 | Self::Tup9i64(_) => Self::TUP9_I64_CODE, |
| 902 | Self::Tup10i64(_) => Self::TUP10_I64_CODE, |
| 903 | |
| 904 | //// Scheduled for removal |
| 905 | //Self::PartKey(_) => Self::PARTKEY_CODE, |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /// Used by `IterDat`. |
| 910 | pub fn must_iterdat_flatten(&self) -> bool { |
| 911 | match self { |
| 912 | // Atomic Kinds =========================== |
| 913 | // Logic |
| 914 | Self::Empty | |
| 915 | Self::Bool(_) | |
| 916 | // Fixed |
| 917 | Self::U8(_) | |
| 918 | Self::U16(_) | |
| 919 | Self::U32(_) | |
| 920 | Self::U64(_) | |
| 921 | Self::U128(_) | |
| 922 | Self::I8(_) | |
| 923 | Self::I16(_) | |
| 924 | Self::I32(_) | |
| 925 | Self::I64(_) | |
| 926 | Self::I128(_) | |
| 927 | Self::F32(_) | |
| 928 | Self::F64(_) | |
| 929 | // Variable |
| 930 | Self::Aint(_) | |
| 931 | Self::Adec(_) | |
| 932 | Self::C64(_) | |
| 933 | Self::Str(_) | |
| 934 | // Molecular Kinds ======================== |
| 935 | // Unitary |
| 936 | Self::Usr(_, _) | |
| 937 | Self::Box(_) | |
| 938 | Self::Opt(_) => false, |
| 939 | _ => true, |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /// Used by `IterDatValsMut`. |
| 944 | pub fn must_iterdatvalsmut_flatten(&self) -> bool { |
| 945 | match self { |
| 946 | // Heterogenous |
| 947 | Self::List(_) | |
| 948 | Self::Tup2(_) | |
| 949 | Self::Tup3(_) | |
| 950 | Self::Tup4(_) | |
| 951 | Self::Tup5(_) | |
| 952 | Self::Tup6(_) | |
| 953 | Self::Tup7(_) | |
| 954 | Self::Tup8(_) | |
| 955 | Self::Tup9(_) | |
| 956 | Self::Tup10(_) | |
| 957 | Self::Map(_) | |
| 958 | Self::OrdMap(_) | |
| 959 | // Homogenous |
| 960 | Self::Vek(_) => true, |
| 961 | _ => false, |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | impl Default for Kind { |
| 967 | fn default() -> Self { |
| 968 | Self::Unknown |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | impl fmt::Display for Kind { |
| 973 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 974 | match self { |
| 975 | Self::Unknown => f.write_str("unknown"), |
| 976 | // Atomic Kinds =========================== |
| 977 | // Logic |
| 978 | Self::Empty => f.write_str("empty"), |
| 979 | //Self::Bool => f.write_str("BOOL"), |
| 980 | Self::True => f.write_str("true"), |
| 981 | Self::False => f.write_str("false"), |
| 982 | Self::None => f.write_str("none"), |
| 983 | // Fixed |
| 984 | Self::U8 => f.write_str("u8"), |
| 985 | Self::U16 => f.write_str("u16"), |
| 986 | Self::U32 => f.write_str("u32"), |
| 987 | Self::U64 => f.write_str("u64"), |
| 988 | Self::U128 => f.write_str("u128"), |
| 989 | Self::I8 => f.write_str("i8"), |
| 990 | Self::I16 => f.write_str("i16"), |
| 991 | Self::I32 => f.write_str("i32"), |
| 992 | Self::I64 => f.write_str("i64"), |
| 993 | Self::I128 => f.write_str("i128"), |
| 994 | Self::F32 => f.write_str("f32"), |
| 995 | Self::F64 => f.write_str("f64"), |
| 996 | // Variable |
| 997 | Self::Aint => f.write_str("aint"), |
| 998 | Self::Adec => f.write_str("adec"), |
| 999 | Self::C64 => f.write_str("c64"), |
| 1000 | Self::Str => f.write_str("str"), |
| 1001 | // Molecule Kinds ========================= |
| 1002 | // Unitary |
| 1003 | Self::Usr(ukid) => write!(f, "usr({})", ukid.label()), |
| 1004 | Self::Box(_) => f.write_str("box"), |
| 1005 | Self::Some(_) => f.write_str("some"), |
| 1006 | Self::ABox(_) => f.write_str("abox"), |
| 1007 | // Heterogenous |
| 1008 | Self::List => f.write_str("list"), |
| 1009 | Self::Tup2 => f.write_str("t2"), |
| 1010 | Self::Tup3 => f.write_str("t3"), |
| 1011 | Self::Tup4 => f.write_str("t4"), |
| 1012 | Self::Tup5 => f.write_str("t5"), |
| 1013 | Self::Tup6 => f.write_str("t6"), |
| 1014 | Self::Tup7 => f.write_str("t7"), |
| 1015 | Self::Tup8 => f.write_str("t8"), |
| 1016 | Self::Tup9 => f.write_str("t9"), |
| 1017 | Self::Tup10 => f.write_str("t10"), |
| 1018 | Self::Map => f.write_str("map"), |
| 1019 | Self::OrdMap => f.write_str("omap"), |
| 1020 | // Homogenous |
| 1021 | Self::Vek => f.write_str("vek"), |
| 1022 | // Variable length bytes - length itself is encoded as a u8, u16, ... |
| 1023 | Self::BU8 => f.write_str("bu8"), |
| 1024 | Self::BU16 => f.write_str("bu16"), |
| 1025 | Self::BU32 => f.write_str("bu32"), |
| 1026 | Self::BU64 => f.write_str("bu64"), |
| 1027 | Self::BC64 => f.write_str("bc64"), |
| 1028 | // Fixed length bytes |
| 1029 | Self::B2 => f.write_str("b2"), |
| 1030 | Self::B3 => f.write_str("b3"), |
| 1031 | Self::B4 => f.write_str("b4"), |
| 1032 | Self::B5 => f.write_str("b5"), |
| 1033 | Self::B6 => f.write_str("b6"), |
| 1034 | Self::B7 => f.write_str("b7"), |
| 1035 | Self::B8 => f.write_str("b8"), |
| 1036 | Self::B9 => f.write_str("b9"), |
| 1037 | Self::B10 => f.write_str("b10"), |
| 1038 | Self::B16 => f.write_str("b16"), |
| 1039 | Self::B32 => f.write_str("b32"), |
| 1040 | // Variable length numbers |
| 1041 | Self::Vu16 => f.write_str("vu16"), |
| 1042 | Self::Vu32 => f.write_str("vu32"), |
| 1043 | Self::Vu64 => f.write_str("vu64"), |
| 1044 | Self::Vu128 => f.write_str("vu128"), |
| 1045 | Self::Vi8 => f.write_str("vi8"), |
| 1046 | Self::Vi16 => f.write_str("vi16"), |
| 1047 | Self::Vi32 => f.write_str("vi32"), |
| 1048 | Self::Vi64 => f.write_str("vi64"), |
| 1049 | Self::Vi128 => f.write_str("vi128"), |
| 1050 | // Fixed length numbers |
| 1051 | // u16 tuples |
| 1052 | Self::Tup2u16 => f.write_str("t2u16"), |
| 1053 | Self::Tup3u16 => f.write_str("t3u16"), |
| 1054 | Self::Tup4u16 => f.write_str("t4u16"), |
| 1055 | Self::Tup5u16 => f.write_str("t5u16"), |
| 1056 | Self::Tup6u16 => f.write_str("t6u16"), |
| 1057 | Self::Tup7u16 => f.write_str("t7u16"), |
| 1058 | Self::Tup8u16 => f.write_str("t8u16"), |
| 1059 | Self::Tup9u16 => f.write_str("t9u16"), |
| 1060 | Self::Tup10u16 => f.write_str("t10u16"), |
| 1061 | // u32 tuples |
| 1062 | Self::Tup2u32 => f.write_str("t2u32"), |
| 1063 | Self::Tup3u32 => f.write_str("t3u32"), |
| 1064 | Self::Tup4u32 => f.write_str("t4u32"), |
| 1065 | Self::Tup5u32 => f.write_str("t5u32"), |
| 1066 | Self::Tup6u32 => f.write_str("t6u32"), |
| 1067 | Self::Tup7u32 => f.write_str("t7u32"), |
| 1068 | Self::Tup8u32 => f.write_str("t8u32"), |
| 1069 | Self::Tup9u32 => f.write_str("t9u32"), |
| 1070 | Self::Tup10u32 => f.write_str("t10u32"), |
| 1071 | // u64 tuples |
| 1072 | Self::Tup2u64 => f.write_str("t2u64"), |
| 1073 | Self::Tup3u64 => f.write_str("t3u64"), |
| 1074 | Self::Tup4u64 => f.write_str("t4u64"), |
| 1075 | Self::Tup5u64 => f.write_str("t5u64"), |
| 1076 | Self::Tup6u64 => f.write_str("t6u64"), |
| 1077 | Self::Tup7u64 => f.write_str("t7u64"), |
| 1078 | Self::Tup8u64 => f.write_str("t8u64"), |
| 1079 | Self::Tup9u64 => f.write_str("t9u64"), |
| 1080 | Self::Tup10u64 => f.write_str("t10u64"), |
| 1081 | // u8 tuples |
| 1082 | Self::Tup2u8 => f.write_str("t2u8"), |
| 1083 | Self::Tup3u8 => f.write_str("t3u8"), |
| 1084 | Self::Tup4u8 => f.write_str("t4u8"), |
| 1085 | Self::Tup5u8 => f.write_str("t5u8"), |
| 1086 | Self::Tup6u8 => f.write_str("t6u8"), |
| 1087 | Self::Tup7u8 => f.write_str("t7u8"), |
| 1088 | Self::Tup8u8 => f.write_str("t8u8"), |
| 1089 | Self::Tup9u8 => f.write_str("t9u8"), |
| 1090 | Self::Tup10u8 => f.write_str("t10u8"), |
| 1091 | // i8 tuples |
| 1092 | Self::Tup2i8 => f.write_str("t2i8"), |
| 1093 | Self::Tup3i8 => f.write_str("t3i8"), |
| 1094 | Self::Tup4i8 => f.write_str("t4i8"), |
| 1095 | Self::Tup5i8 => f.write_str("t5i8"), |
| 1096 | Self::Tup6i8 => f.write_str("t6i8"), |
| 1097 | Self::Tup7i8 => f.write_str("t7i8"), |
| 1098 | Self::Tup8i8 => f.write_str("t8i8"), |
| 1099 | Self::Tup9i8 => f.write_str("t9i8"), |
| 1100 | Self::Tup10i8 => f.write_str("t10i8"), |
| 1101 | // i16 tuples |
| 1102 | Self::Tup2i16 => f.write_str("t2i16"), |
| 1103 | Self::Tup3i16 => f.write_str("t3i16"), |
| 1104 | Self::Tup4i16 => f.write_str("t4i16"), |
| 1105 | Self::Tup5i16 => f.write_str("t5i16"), |
| 1106 | Self::Tup6i16 => f.write_str("t6i16"), |
| 1107 | Self::Tup7i16 => f.write_str("t7i16"), |
| 1108 | Self::Tup8i16 => f.write_str("t8i16"), |
| 1109 | Self::Tup9i16 => f.write_str("t9i16"), |
| 1110 | Self::Tup10i16 => f.write_str("t10i16"), |
| 1111 | // i32 tuples |
| 1112 | Self::Tup2i32 => f.write_str("t2i32"), |
| 1113 | Self::Tup3i32 => f.write_str("t3i32"), |
| 1114 | Self::Tup4i32 => f.write_str("t4i32"), |
| 1115 | Self::Tup5i32 => f.write_str("t5i32"), |
| 1116 | Self::Tup6i32 => f.write_str("t6i32"), |
| 1117 | Self::Tup7i32 => f.write_str("t7i32"), |
| 1118 | Self::Tup8i32 => f.write_str("t8i32"), |
| 1119 | Self::Tup9i32 => f.write_str("t9i32"), |
| 1120 | Self::Tup10i32 => f.write_str("t10i32"), |
| 1121 | // i64 tuples |
| 1122 | Self::Tup2i64 => f.write_str("t2i64"), |
| 1123 | Self::Tup3i64 => f.write_str("t3i64"), |
| 1124 | Self::Tup4i64 => f.write_str("t4i64"), |
| 1125 | Self::Tup5i64 => f.write_str("t5i64"), |
| 1126 | Self::Tup6i64 => f.write_str("t6i64"), |
| 1127 | Self::Tup7i64 => f.write_str("t7i64"), |
| 1128 | Self::Tup8i64 => f.write_str("t8i64"), |
| 1129 | Self::Tup9i64 => f.write_str("t9i64"), |
| 1130 | Self::Tup10i64 => f.write_str("t10i64"), |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | impl FromStr for Kind { |
| 1136 | type Err = Error<ErrTag>; |
| 1137 | |
| 1138 | fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { |
| 1139 | match s.to_lowercase().as_str() { |
| 1140 | // Atomic Kinds =========================== |
| 1141 | // Logic |
| 1142 | "empty" => Ok(Self::Empty), |
| 1143 | "true" => Ok(Self::True), |
| 1144 | "false" => Ok(Self::False), |
| 1145 | // `none` is JDAT's keyword; `null` is accepted as an |
| 1146 | // alias so any RFC 8259 JSON document decodes through |
| 1147 | // `Dat::decode_string` without pre-processing. |
| 1148 | "none" | "null" => Ok(Self::None), |
| 1149 | // Fixed |
| 1150 | "u8" => Ok(Self::U8), |
| 1151 | "u16" => Ok(Self::U16), |
| 1152 | "u32" => Ok(Self::U32), |
| 1153 | "u64" => Ok(Self::U64), |
| 1154 | "u128" => Ok(Self::U128), |
| 1155 | "i8" => Ok(Self::I8), |
| 1156 | "i16" => Ok(Self::I16), |
| 1157 | "i32" => Ok(Self::I32), |
| 1158 | "i64" => Ok(Self::I64), |
| 1159 | "i128" => Ok(Self::I128), |
| 1160 | "f32" => Ok(Self::F32), |
| 1161 | "f64" => Ok(Self::F64), |
| 1162 | // Variable |
| 1163 | "aint" => Ok(Self::Aint), |
| 1164 | "adec" => Ok(Self::Adec), |
| 1165 | "c64" => Ok(Self::C64), |
| 1166 | "str" => Ok(Self::Str), |
| 1167 | // Molecule Kinds ========================= |
| 1168 | // Unitary |
| 1169 | "box" => Ok(Self::Box(None)), |
| 1170 | "some" => Ok(Self::Some(None)), |
| 1171 | "abox" => Ok(Self::ABox(None)), |
| 1172 | // Heterogenous |
| 1173 | "list" => Ok(Self::List), |
| 1174 | "t2" => Ok(Self::Tup2), |
| 1175 | "t3" => Ok(Self::Tup3), |
| 1176 | "t4" => Ok(Self::Tup4), |
| 1177 | "t5" => Ok(Self::Tup5), |
| 1178 | "t6" => Ok(Self::Tup6), |
| 1179 | "t7" => Ok(Self::Tup7), |
| 1180 | "t8" => Ok(Self::Tup8), |
| 1181 | "t9" => Ok(Self::Tup9), |
| 1182 | "t10" => Ok(Self::Tup10), |
| 1183 | "map" => Ok(Self::Map), |
| 1184 | "omap" => Ok(Self::OrdMap), |
| 1185 | // Homogenous |
| 1186 | "vek" => Ok(Self::Vek), |
| 1187 | // Variable length bytes |
| 1188 | "bu8" => Ok(Self::BU8), |
| 1189 | "bu16" => Ok(Self::BU16), |
| 1190 | "bu32" => Ok(Self::BU32), |
| 1191 | "bu64" => Ok(Self::BU64), |
| 1192 | "bc64" => Ok(Self::BC64), |
| 1193 | // Fixed length bytes |
| 1194 | "b2" => Ok(Self::B2), |
| 1195 | "b3" => Ok(Self::B3), |
| 1196 | "b4" => Ok(Self::B4), |
| 1197 | "b5" => Ok(Self::B5), |
| 1198 | "b6" => Ok(Self::B6), |
| 1199 | "b7" => Ok(Self::B7), |
| 1200 | "b8" => Ok(Self::B8), |
| 1201 | "b9" => Ok(Self::B9), |
| 1202 | "b10" => Ok(Self::B10), |
| 1203 | "b16" => Ok(Self::B16), |
| 1204 | "b32" => Ok(Self::B32), |
| 1205 | // Fixed length numbers |
| 1206 | "t2u16" => Ok(Self::Tup2u16), |
| 1207 | "t3u16" => Ok(Self::Tup3u16), |
| 1208 | "t4u16" => Ok(Self::Tup4u16), |
| 1209 | "t5u16" => Ok(Self::Tup5u16), |
| 1210 | "t6u16" => Ok(Self::Tup6u16), |
| 1211 | "t7u16" => Ok(Self::Tup7u16), |
| 1212 | "t8u16" => Ok(Self::Tup8u16), |
| 1213 | "t9u16" => Ok(Self::Tup9u16), |
| 1214 | "t10u16" => Ok(Self::Tup10u16), |
| 1215 | "t2u32" => Ok(Self::Tup2u32), |
| 1216 | "t3u32" => Ok(Self::Tup3u32), |
| 1217 | "t4u32" => Ok(Self::Tup4u32), |
| 1218 | "t5u32" => Ok(Self::Tup5u32), |
| 1219 | "t6u32" => Ok(Self::Tup6u32), |
| 1220 | "t7u32" => Ok(Self::Tup7u32), |
| 1221 | "t8u32" => Ok(Self::Tup8u32), |
| 1222 | "t9u32" => Ok(Self::Tup9u32), |
| 1223 | "t10u32" => Ok(Self::Tup10u32), |
| 1224 | "t2u64" => Ok(Self::Tup2u64), |
| 1225 | "t3u64" => Ok(Self::Tup3u64), |
| 1226 | "t4u64" => Ok(Self::Tup4u64), |
| 1227 | "t5u64" => Ok(Self::Tup5u64), |
| 1228 | "t6u64" => Ok(Self::Tup6u64), |
| 1229 | "t7u64" => Ok(Self::Tup7u64), |
| 1230 | "t8u64" => Ok(Self::Tup8u64), |
| 1231 | "t9u64" => Ok(Self::Tup9u64), |
| 1232 | "t10u64" => Ok(Self::Tup10u64), |
| 1233 | |
| 1234 | _ => Err(err!( |
| 1235 | "Daticle kind label not recognised as standard: '{}'", s; |
| 1236 | Input, String, Unknown)), |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 |