Skip to content

Commit

Permalink
Start v1-v2 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Sep 17, 2024
1 parent 2923488 commit f421515
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/meta/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::*;
use super::Distribution;
use serde_json::Value;
use std::error::Error;

pub fn from_value(meta: Value) -> Result<Distribution, Box<dyn Error>> {
match serde_json::from_value(meta) {
Expand Down
14 changes: 7 additions & 7 deletions src/release/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{borrow::Borrow, collections::HashMap, error::Error, fs::File, path::Path};

mod v1;
mod v2;

/// Digests represents Hash digests for a file that can be used to verify its
/// integrity.
#[serde_with::serde_as]
Expand Down Expand Up @@ -142,15 +145,12 @@ impl Release {
// copy/pasting all the Distribution methods, but this will do for now.
// [delegation]: https://github.com/rust-lang/rfcs/pull/3530

/// Deserializes `meta`, which contains PGXN disribution release metadata,
/// into a [`Release`].
/// Deserializes `meta`, which contains PGXN distribution release
/// metadata, into a [`Release`].
fn from_version(version: u8, meta: Value) -> Result<Self, Box<dyn Error>> {
match version {
// 1 => v1::from_value(meta),
2 => match serde_json::from_value(meta) {
Ok(m) => Ok(m),
Err(e) => Err(Box::from(e)),
},
1 => v1::from_value(meta),
2 => v2::from_value(meta),
_ => Err(Box::from(format!("Unknown meta version {version}"))),
}

Expand Down
7 changes: 7 additions & 0 deletions src/release/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::Release;
use serde_json::Value;
use std::error::Error;

pub fn from_value(_: Value) -> Result<Release, Box<dyn Error>> {
Err("TODO".into())
}
10 changes: 10 additions & 0 deletions src/release/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use super::Release;
use serde_json::Value;
use std::error::Error;

pub fn from_value(meta: Value) -> Result<Release, Box<dyn Error>> {
match serde_json::from_value(meta) {
Ok(m) => Ok(m),
Err(e) => Err(Box::from(e)),
}
}

0 comments on commit f421515

Please sign in to comment.