-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from stepchowfun/permissive-signatures
Make some type signatures more permissive
- Loading branch information
Showing
10 changed files
with
237 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "typical" | ||
version = "0.12.0" | ||
version = "0.12.1" | ||
authors = ["Stephan Boyer <[email protected]>"] | ||
edition = "2021" | ||
description = "Data interchange with algebraic data types." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ mod types; | |
use { | ||
std::{ | ||
fs::{remove_file, File}, | ||
io::{self, BufReader, BufWriter}, | ||
io::{self, BufReader, BufWriter, Write}, | ||
}, | ||
types::{ | ||
types::{ | ||
|
@@ -16,7 +16,7 @@ use { | |
const REQUEST_FILE_PATH: &str = "/tmp/request"; | ||
const RESPONSE_FILE_PATH: &str = "/tmp/response"; | ||
|
||
fn write_to_file() -> io::Result<()> { | ||
fn write_to_files() -> io::Result<()> { | ||
let request_message = SendEmailRequestOut { | ||
to: "[email protected]".to_owned(), | ||
subject: "I love Typical!".to_owned(), | ||
|
@@ -25,14 +25,16 @@ fn write_to_file() -> io::Result<()> { | |
|
||
let response_message = SendEmailResponseOut::Error("Example error".to_string()); | ||
|
||
let request_file = BufWriter::new(File::create(REQUEST_FILE_PATH)?); | ||
request_message.serialize(request_file)?; | ||
let mut request_file = BufWriter::new(File::create(REQUEST_FILE_PATH)?); | ||
request_message.serialize(&mut request_file)?; | ||
request_file.flush()?; | ||
|
||
let response_file = BufWriter::new(File::create(RESPONSE_FILE_PATH)?); | ||
response_message.serialize(response_file) | ||
let mut response_file = BufWriter::new(File::create(RESPONSE_FILE_PATH)?); | ||
response_message.serialize(&mut response_file)?; | ||
response_file.flush() | ||
} | ||
|
||
fn read_from_file() -> io::Result<()> { | ||
fn read_from_files() -> io::Result<()> { | ||
let request_file = BufReader::new(File::open(REQUEST_FILE_PATH)?); | ||
let request_message = SendEmailRequestIn::deserialize(request_file)?; | ||
|
||
|
@@ -52,8 +54,8 @@ fn read_from_file() -> io::Result<()> { | |
} | ||
|
||
fn main() -> io::Result<()> { | ||
write_to_file()?; | ||
read_from_file()?; | ||
write_to_files()?; | ||
read_from_files()?; | ||
remove_file(REQUEST_FILE_PATH)?; | ||
remove_file(RESPONSE_FILE_PATH) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ const requestFilePath = '/tmp/request'; | |
const responseFilePath = '/tmp/response'; | ||
const { SendEmailRequest, SendEmailResponse } = Types; | ||
|
||
function writeToFile(): void { | ||
function writeToFiles(): void { | ||
const requestMessage = { | ||
to: '[email protected]', | ||
subject: 'I love Typical!', | ||
|
@@ -23,29 +23,15 @@ function writeToFile(): void { | |
writeFileSync(responseFilePath, Buffer.from(responseArrayBuffer)); | ||
} | ||
|
||
function readFromFile(): void { | ||
function readFromFiles(): void { | ||
const requestFileContents = readFileSync(requestFilePath); | ||
const requestMessage = SendEmailRequest.deserialize( | ||
new DataView( | ||
requestFileContents.buffer, | ||
requestFileContents.byteOffset, | ||
requestFileContents.byteLength, | ||
), | ||
); | ||
|
||
const requestMessage = SendEmailRequest.deserialize(requestFileContents); | ||
if (requestMessage instanceof Error) { | ||
throw requestMessage; | ||
} | ||
|
||
const responseFileContents = readFileSync(responseFilePath); | ||
const responseMessage = SendEmailResponse.deserialize( | ||
new DataView( | ||
responseFileContents.buffer, | ||
responseFileContents.byteOffset, | ||
responseFileContents.byteLength, | ||
), | ||
); | ||
|
||
const responseMessage = SendEmailResponse.deserialize(responseFileContents); | ||
if (responseMessage instanceof Error) { | ||
throw responseMessage; | ||
} | ||
|
@@ -72,7 +58,7 @@ function readFromFile(): void { | |
return undefined; // To satisfy ESLint's `consistent-return` rule | ||
} | ||
|
||
writeToFile(); | ||
readFromFile(); | ||
writeToFiles(); | ||
readFromFiles(); | ||
unlinkSync(requestFilePath); | ||
unlinkSync(responseFilePath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.