-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generator/rust): introduce dyn-compatible traits (#375)
These are generated, but not used, for now.
- Loading branch information
Showing
35 changed files
with
2,184 additions
and
0 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
generator/templates/rust/crate/src/traits/dyntraits.rs.mustache
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{{! | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
}} | ||
// Copyright {{CopyrightYear}} Google LLC | ||
{{#BoilerPlate}} | ||
//{{{.}}} | ||
{{/BoilerPlate}} | ||
{{#Services}} | ||
|
||
/// A dyn-compatible, crate-private version of `{{NameToPascal}}`. | ||
#[async_trait::async_trait] | ||
pub trait {{NameToPascal}}: Send + Sync { | ||
{{#Methods}} | ||
{{#DocLines}} | ||
{{{.}}} | ||
{{/DocLines}} | ||
async fn {{NameToSnake}}( | ||
&self, | ||
req: {{InputTypeName}} | ||
) -> crate::Result<{{OutputTypeName}}>; | ||
|
||
{{/Methods}} | ||
} | ||
|
||
/// All implementations of [crate::traits::{{NameToPascal}}] also implement [{{NameToPascal}}]. | ||
#[async_trait::async_trait] | ||
impl<T: crate::traits::{{NameToPascal}}> {{NameToPascal}} for T { | ||
{{#Methods}} | ||
/// Forwards the call to the implementation provided by `T`. | ||
async fn {{NameToSnake}}( | ||
&self, | ||
req: {{InputTypeName}} | ||
) -> crate::Result<{{OutputTypeName}}> { | ||
let response = T::{{NameToSnake}}(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
{{/Methods}} | ||
} | ||
{{/Services}} |
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
81 changes: 81 additions & 0 deletions
81
generator/testdata/rust/gclient/golden/iam/v1/src/traits/dyntraits.rs
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Code generated by sidekick. DO NOT EDIT. | ||
|
||
/// A dyn-compatible, crate-private version of `Iampolicy`. | ||
#[async_trait::async_trait] | ||
pub trait Iampolicy: Send + Sync { | ||
/// Sets the access control policy on the specified resource. Replaces any | ||
/// existing policy. | ||
/// | ||
/// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. | ||
async fn set_iam_policy( | ||
&self, | ||
req: crate::model::SetIamPolicyRequest | ||
) -> crate::Result<crate::model::Policy>; | ||
|
||
/// Gets the access control policy for a resource. | ||
/// Returns an empty policy if the resource exists and does not have a policy | ||
/// set. | ||
async fn get_iam_policy( | ||
&self, | ||
req: crate::model::GetIamPolicyRequest | ||
) -> crate::Result<crate::model::Policy>; | ||
|
||
/// Returns permissions that a caller has on the specified resource. | ||
/// If the resource does not exist, this will return an empty set of | ||
/// permissions, not a `NOT_FOUND` error. | ||
/// | ||
/// Note: This operation is designed to be used for building permission-aware | ||
/// UIs and command-line tools, not for authorization checking. This operation | ||
/// may "fail open" without warning. | ||
async fn test_iam_permissions( | ||
&self, | ||
req: crate::model::TestIamPermissionsRequest | ||
) -> crate::Result<crate::model::TestIamPermissionsResponse>; | ||
|
||
} | ||
|
||
/// All implementations of [crate::traits::Iampolicy] also implement [Iampolicy]. | ||
#[async_trait::async_trait] | ||
impl<T: crate::traits::Iampolicy> Iampolicy for T { | ||
/// Forwards the call to the implementation provided by `T`. | ||
async fn set_iam_policy( | ||
&self, | ||
req: crate::model::SetIamPolicyRequest | ||
) -> crate::Result<crate::model::Policy> { | ||
let response = T::set_iam_policy(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
/// Forwards the call to the implementation provided by `T`. | ||
async fn get_iam_policy( | ||
&self, | ||
req: crate::model::GetIamPolicyRequest | ||
) -> crate::Result<crate::model::Policy> { | ||
let response = T::get_iam_policy(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
/// Forwards the call to the implementation provided by `T`. | ||
async fn test_iam_permissions( | ||
&self, | ||
req: crate::model::TestIamPermissionsRequest | ||
) -> crate::Result<crate::model::TestIamPermissionsResponse> { | ||
let response = T::test_iam_permissions(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
generator/testdata/rust/gclient/golden/location/src/traits/dyntraits.rs
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Code generated by sidekick. DO NOT EDIT. | ||
|
||
/// A dyn-compatible, crate-private version of `Locations`. | ||
#[async_trait::async_trait] | ||
pub trait Locations: Send + Sync { | ||
/// Lists information about the supported locations for this service. | ||
async fn list_locations( | ||
&self, | ||
req: crate::model::ListLocationsRequest | ||
) -> crate::Result<crate::model::ListLocationsResponse>; | ||
|
||
/// Gets information about a location. | ||
async fn get_location( | ||
&self, | ||
req: crate::model::GetLocationRequest | ||
) -> crate::Result<crate::model::Location>; | ||
|
||
} | ||
|
||
/// All implementations of [crate::traits::Locations] also implement [Locations]. | ||
#[async_trait::async_trait] | ||
impl<T: crate::traits::Locations> Locations for T { | ||
/// Forwards the call to the implementation provided by `T`. | ||
async fn list_locations( | ||
&self, | ||
req: crate::model::ListLocationsRequest | ||
) -> crate::Result<crate::model::ListLocationsResponse> { | ||
let response = T::list_locations(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
/// Forwards the call to the implementation provided by `T`. | ||
async fn get_location( | ||
&self, | ||
req: crate::model::GetLocationRequest | ||
) -> crate::Result<crate::model::Location> { | ||
let response = T::get_location(self, req).await?; | ||
Ok(response) | ||
} | ||
|
||
} |
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.